tags:

views:

122

answers:

1

I cannot seem to get the following to work

directory <- "./"
files.15x16 <- c("15x16-70d.out", "15x16-71d.out")
data.15x16<-rbind( lapply( as.array(paste(directory, files.15x16, sep="")), FUN=read.csv, sep=" ", header=F) )

What it should be doing is pretty straightforward - I have a directory name, some file names, and actual files of data. I paste the directory and file names together, read the data from the files in, and then rbind them all together into a single chunk of data.

Except the result of the lapply has the data in [[]] - i.e., accessing it occurs via a[[1]], a[[2]], etc which rbind doesn't seem to accept.

Suggestions?

+8  A: 

Use do.call:

data.15x16 <-  do.call(rbind, lapply(paste(directory, files.15x16, sep=""), 
                                      FUN=read.csv, sep=" ", header=F)) 

You also don't need the as.array - it does not really do anything here.

Aniko
brilliant, thanks; as.array was a leftover from using apply instead of lapply - apply was complaining about dim(X) not being positive
Carl