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



Enjoyed this article? I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter, Facebook or Linked In.

Show me some love with the like buttons below... Thank you and please don't forget to share and comment below!!
Avez vous aimé cet article? Je vous serais très reconnaissant si vous aidiez à sa diffusion en l'envoyant par courriel à un ami ou en le partageant sur Twitter, Facebook ou Linked In.

Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, s'il vous plaît, de partager et de commenter ci-dessous!





This page has been seen 180844 times