I often find myself (wanting t)o constructing lists or data.frames like so: #Find files in subdirs ii <- 0 for (ix in id) { ii <- ii + 1 if (ii == 1) { fl <- list(basename(ix) = list.files(ix)) } else { fl <- c(fl, list(basename(ix) = list.files(ix))) } } The above is for list construction. It does not work as the argument name is not accepted. In python this would be legal but I can't find how to modify the name argument in R to make this legal. Furthermore the use of a separate counter is not very elegant. Would there be a better way? Again, in python appending to a list is very easy but seems to be available in R only for vectors not lists? Any help much appreciated! Alex van der Spek
> I often find myself (wanting t)o constructing lists or > data.frames:Try something like fl<-list() for (ix in id) { fl[[basename(ix)]] <- list.files(ix) } But read R Inferno on inrementing objects first. It isn't efficient in memory terms (unless that's improved in recent versions of R) Rather more elegantly you can get the same list with sapply(id, function(ix) list.files(ix)) ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
> I often find myself (wanting t)o constructing lists or > data.framesApologies; previous post should have said "Read R inforno on 'Growing Objects'" and should have added the URL: http://www.burns-stat.com/pages/Tutor/R_inferno.pdf S Ellison ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}