Quantcast
Channel: Easy Guides
Viewing all articles
Browse latest Browse all 183

Importing Data Into R

$
0
0


In the previous chapter we described the essentials of R programming. Here, you’ll learn how to import data from txt, csv, Excel (xls, xlsx) into R.


Importing data into R



  1. Best practices in preparing data files for importing into R

Excel file

Read more: Best practices in preparing data files for importing into R

  1. Reading data from txt|csv files: R base functions
  • R base functions for importing data: read.table(), read.delim(), read.csv(), read.csv2()
  • Reading a local file
  • Reading a file from internet

Reading Data From txt|csv Files: R Base Functions

# Read tab separated values
read.delim(file.choose())

# Read comma (",") separated values
read.csv(file.choose())

# Read semicolon (";") separated values
read.csv2(file.choose())

Read more: Reading data from txt|csv files: R base functions



  1. Fast Reading of Data From txt|csv Files into R: readr package
  • Functions for reading txt|csv files: read_delim(), read_tsv(), read_csv(), read_csv2()
  • Reading a file
    • Reading a local file
    • Reading a file from internet
    • In the case of parsing problems
  • Specify column types
  • Reading lines from a file: read_lines()
  • Read whole file: read_file()

Reading Data From txt|csv Files: readr package

library("readr")

# Read tab separated values
read_tsv(file.choose())

# Read comma (",") separated values
read_csv(file.choose())

# Read semicolon (";") separated values
read_csv2(file.choose())

Read more: Fast Reading of Data From txt|csv Files into R: readr package



  1. Reading data From Excel Files (xls|xlsx) into R
  • Copying data from Excel and import into R
  • Importing Excel files into R using readxl package
  • Importing Excel files using xlsx package

Reading Data From Excel Files (xls|xlsx) into R

# Use readxl package to read xls|xlsx
library("readxl")
my_data <- read_excel("my_file.xlsx")

# Use xlsx package
library("xlsx")
my_data <- read.xlsx("my_file.xlsx") 

Read more: Reading data From Excel Files (xls|xlsx) into R



Viewing all articles
Browse latest Browse all 183

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>