Skip to content
Prev 30394 / 398528 Next

Reading in multiple files

On Wed, 9 Apr 2003, Bliese, Paul D MAJ WRAIR-Wash DC wrote:

            
You can get the file list with

   all.the.files <- list.files("C:/temp",full=TRUE)

where full=TRUE asks for absolute file paths, which will be useful if this
isn't your working directory. You could also add pattern="\\.csv$" to
ensure that you only get .csv files.


Then you could read them all in

  all.the.data <- lapply( all.the.files,  read.csv, header=TRUE)

and then rbind them into a data frame

  DATA <- do.call("rbind", all.the.data)

In one line this would be

DATA <- do.call("rbind", lapply( list.files("C:/temp",full=TRUE),
		read.csv, header=TRUE))


It should be faster to use do.call("rbind",) rather than a loop, but I
don't know if it actually is.


	-thomas