[R] syntax for batching rbind process

Toby Gass tobygass at warnercnr.colostate.edu
Wed Aug 18 20:46:03 CEST 2010


Dear helpeRs,

I am attempting to read in a series of csv files so I can bind them 
into one large dataframe.  I have written the following script:

test <- list.files(".", pattern = "csv")  #lline 1
imp <- list()                                    #line 2
for (i in 1:length(test)) {                    #line 3
imp[i] <- read.csv(test[i])                  #line 4
}                                                    #line 5
works <- do.call(rbind, imp)              #line 6
write.csv(works, "allmet.csv")           #line 7

This script has an error at line 4.  imp[i] contains only the value 
of the first element of test[i]; in other words, every element of 
imp[i] equals test[i] [1,1].  Otherwise, the script works.  Could 
someone please enlighten me as to the correct syntax for line 4?

Thank you in advance.

Toby



More information about the R-help mailing list