Importing Data Into R


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










Want to Learn More on R Programming and Data Science?

Follow us by Email

by FeedBurner

On Social Networks:


 Get involved :
  Click to follow us on and Google+ :   
  Comment this article by clicking on "Discussion" button (top-right position of this page)
  Sign up as a member and post news and articles on STHDA web site.


Articles contained by this category :  

Best Practices in Preparing Data Files for Importing into R
Fast Reading of Data From TXT|CSV Files into R: readr package
Reading Data From Excel Files (xls|xlsx) into R
Reading Data From TXT|CSV Files: R Base Functions
This page has been seen 7788 times