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,418
  • 3
  • 19
  • 23
REnthusiast
  • 1,591
  • 3
  • 16
  • 18
  • For the code dataFiles <- lapply(Sys.glob("data*.csv"), read.csv) do I need to have data in front of the names of my .csv files? Thanks? – REnthusiast Jun 24 '13 at 09:16
  • Yes indeed, or you can of course adapt the code based on how your files are named. – RenéR Jun 24 '13 at 09:49

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
  • 5,178
  • 8
  • 38
  • 62