On Wed, Mar 24, 2010 at 8:52 AM, mgierdal <mgier...@gmail.com> wrote: > > I have a dataFrame variable: > > L1 L2 L3 ... v1 v2 ... > 1 > 2 > 3 > 4 > ... > > I want to process subsets of it as defined by combinations of L1-L2-L3. I do > it successfully using nested loops: > > for (i in valuesOfL1 { > for (j in valuesOfL2) { > for (k in valuesOfL3) { > tempData <- subset(dataFrame, (L1 == i & L2 == j & L3 == k, > select=c(v1,v2) )) > if (dim(tempData)[1]>0) # does this combination of L1-L2-L3 contain > any data? > { process(tempData) } > } > } > } > > It works fine but: > 1. I'm sure there can be more efficient solution > 2. each time I want to change criteria (i.e. subset by less or more Ls) I > have to manually change number of nested loops in my code.
?split library(plyr) ?ddply Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ ______________________________________________ R-help@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.