[R] list construction with automatic names

S Ellison S.Ellison at lgcgroup.com
Thu Jul 4 14:17:00 CEST 2013


> 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}}



More information about the R-help mailing list