On Tue, Oct 13, 2009 at 6:57 AM, Ista Zahn <istaz...@gmail.com> wrote:
> I'm sure there's a really cool way to do this with plyr, although I
> don't know if my particular plyr version is much better. Anyway here
> it is:
>
> cmbine <- read.csv(textConnection('names, mass, classes
> apple,0.50,1
> tiger,100.00,2
> pencil,0.01,3
> chicken,1.00,2
> banana,0.15,1
> pear,0.30,1'))
>
> library(plyr)
>
> dfl <- list()
>
> for(i in 1:max(cmbine$classes)) {
>  dfl[[i]] <- ddply(cmbine, .(classes), function(x) {x[i,]})
> }

Here's another approach:

cmbine <- read.csv(textConnection('names, mass, classes
apple,0.50,1
tiger,100.00,2
pencil,0.01,3
chicken,1.00,2
banana,0.15,1
pear,0.30,1'))

cmbine <- ddply(cmbine, "classes", transform, i = seq_along(names))
dlply(cmbine, "i")

Hadley

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

Reply via email to