a,b,x,y b,B,2.49778634403711,-0.351307445767206 b,A,-0.594683138631719,1.19629936975021 b,D,1.14857619580259,0.653315728121014 c,A,0.957476532595248,0.935608419299617It's easy to read each one in with

> one = read.csv('1.csv') > nrow(one) [1] 21 > two = read.csv('2.csv') > nrow(two) [1] 25 > three = read.csv('3.csv') > nrow(three) [1] 27 > big = rbind(one,two,three) > nrow(big) [1] 73As I said, that was pretty easy. But now suppose we have 20 csv files that we want to read and combine. We could do what we did with the three files, but, not only would it get tiring, there's a chance of making an error when we have to type so many commands. In the past, when we've had problems like this,

> allframes = sapply(1:20,function(x)read.csv(paste(x,'csv',sep='.'))) > head(allframes) [,1] [,2] [,3] [,4] [,5] [,6] [,7] a factor,21 factor,25 factor,27 factor,25 factor,27 factor,21 factor,24 b factor,21 factor,25 factor,27 factor,25 factor,27 factor,21 factor,24 x Numeric,21 Numeric,25 Numeric,27 Numeric,25 Numeric,27 Numeric,21 Numeric,24 y Numeric,21 Numeric,25 Numeric,27 Numeric,25 Numeric,27 Numeric,21 Numeric,24 [,8] [,9] [,10] [,11] [,12] [,13] [,14] a factor,28 factor,23 factor,23 factor,22 factor,26 factor,24 factor,23 b factor,28 factor,23 factor,23 factor,22 factor,26 factor,24 factor,23 x Numeric,28 Numeric,23 Numeric,23 Numeric,22 Numeric,26 Numeric,24 Numeric,23There were no errors, but the result certainly is strange looking! While we haven't talked about it before, the "s" in

> allframes = lapply(1:20,function(x)read.csv(paste(x,'csv',sep='.'))) > sapply(allframes,nrow) [1] 21 25 27 25 27 21 24 28 23 23 22 26 24 23 25 29 28 30 27 29 > answer = do.call(rbind,allframes) > nrow(answer) [1] 507We can combine all the data frames without storing them separately or passing them individually to

File translated from T

On 28 Feb 2011, 16:55.