1

What code do I need to read multiple data sets into R ?

For a single dataset I use:

File <- read.csv("C:\MyFile.CSV", header=T)

But I need to compare up to 20 different datasets.

Thanks in advance !

Imane Fateh
  • 2,370
  • 3
  • 18
  • 23
REnthusiast
  • 1,531
  • 3
  • 14
  • 18

1 Answers1

1

I would put all the CSV files in a directory, create a list and do a loop to read all the csv files from the directory in the list.

setwd("~/Documents/")
ldf <- list() # creates a list
listcsv <- dir(pattern = "*.csv") # creates the list of all the csv files in the directory
for (k in 1:length(listcsv)){
 ldf[[k]] <- read.csv(listcsv[k])
}
str(ldf[[1]]) 
PAC
  • 4,910
  • 7
  • 37
  • 60