In the previous chapter we described the essentials of R programming. Here, youll learn how to import data from txt, csv, Excel (xls, xlsx) into R.
Read more: Best practices in preparing data files for importing into R
- R base functions for importing data: read.table(), read.delim(), read.csv(), read.csv2()
- Reading a local file
- Reading a file from internet
# 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
- 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()
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
- Copying data from Excel and import into R
- Importing Excel files into R using readxl package
- Importing Excel files using xlsx package
# 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")