Re: [R] split data, but ensure each level of the factor is represented

2008-10-13 Thread Gabor Grothendieck
Try this: split(iris, factor(a, levels = 1:3)) On Mon, Oct 13, 2008 at 1:06 PM, Jay <[EMAIL PROTECTED]> wrote: > Hello, > > I'll use part of the iris dataset for an example of what I want to > do. > >> data(iris) >> iris<-iris[1:10,1:4] >> iris > Sepal.Length Sepal.Width Petal.Length Petal.Widt

Re: [R] split data, but ensure each level of the factor is represented

2008-10-13 Thread Jay
Thanks so much. On Oct 13, 1:14 pm, "Henrique Dallazuanna" <[EMAIL PROTECTED]> wrote: > Try this: > > a<-factor(c(3, 3, 3, 2, 3, 2, 2, 3, 2, 3), levels = 1:3) > split(iris, a) > > lapply(split(iris, a), dim) > > > > On Mon, Oct 13, 2008 at 2:06 PM, Jay <[EMAIL PROTECTED]> wrote: > > Hello, > > > I

Re: [R] split data, but ensure each level of the factor is represented

2008-10-13 Thread Henrique Dallazuanna
Try this: a<-factor(c(3, 3, 3, 2, 3, 2, 2, 3, 2, 3), levels = 1:3) split(iris, a) lapply(split(iris, a), dim) On Mon, Oct 13, 2008 at 2:06 PM, Jay <[EMAIL PROTECTED]> wrote: > Hello, > > I'll use part of the iris dataset for an example of what I want to > do. > > > data(iris) > > iris<-iris[1: