[R] how to assemble data frame of unknown number of columns in loop

From: Nevil Amos <nevil.amos_at_gmail.com>
Date: Sun, 24 Apr 2011 14:44:18 +1000


How do I assemble ad data fame, consisting of columns form other data frames identified in a loop? cbind is not working as the initial data fame has 0 columns and rows.

> ModList<-dir("./MODEL_DISTS/")
> ModList<-ModList[grep(pattern="3COLUMNS",ModList)]
> ALL_MODELS<-data.frame()
> for (i in ModList){

+ X<-read.table(file=paste("./MODEL_DISTS/",i,sep=""))
+ BASE=sub("3COLUMNS","" , i, fixed = TRUE)
+ names(X)<-c("FromSiteID","ToSiteID","CS_RESISTANCE")
+ ALL_MODELS<-cbind(ALL_MODELS,X[3])
+ }

Error in data.frame(..., check.names = FALSE) :

   arguments imply differing number of rows: 0, 2080

thanks



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 24 Apr 2011 - 05:42:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 24 Apr 2011 - 09:00:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive