开发者

R problem with apply + rbind

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 r开发者_JS百科bind doesn't seem to accept.

Suggestions?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜