Skip to content
Back to formatted view

Raw Message

Message-ID: <4DB3DA5A.7020801@xtra.co.nz>
Date: 2011-04-24T08:07:54Z
From: Rolf Turner
Subject: how to assemble data frame of unknown number of columns in loop
In-Reply-To: <4DB3AAA2.2010908@monash.edu>

On 24/04/11 16:44, Nevil Amos wrote:
> 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
Start with ALL_MODELS <- NULL r.t. ALL_MODELS <- data.frame().

     cheers,

             Rolf Turner