Re: [R] collapsing a data frame

2007-10-13 Thread Gabor Grothendieck
The library statement should have been library(doBy). Also note that collapse assumes that all by variables are factors although it would only add one statement to collapse to coerce them to factors if we wanted that. On 10/13/07, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > As far as I know y

Re: [R] collapsing a data frame

2007-10-13 Thread Gabor Grothendieck
As far as I know you will have to do some work yourself but if we leverage some of it off the summaryBy function in doBy its basically just a lapply over the columns. The first arg to collapse is a formula whose rhs contains the by variables and whose lhs is ignored. data is our data frame, fac.f

Re: [R] collapsing a data frame

2007-10-12 Thread hadley wickham
> > Here's a solution that takes the first element of each factor > > and the mean of each numeric variable. I can imagine there > > are more general/flexible solutions. (One might want to > > specify more than one summary function, or specify that > > factors that vary within group should be d

Re: [R] collapsing a data frame

2007-10-12 Thread hadley wickham
On 10/12/07, Ben Bolker <[EMAIL PROTECTED]> wrote: > >Trying to find a quick/slick/easily interpretable way to > collapse a data set. > > Suppose I have a data set that looks like this: > > h <- structure(list(INDEX = structure(1:6, .Label = c("1", "2", "3", > "4", "5", "6"), class = "factor"

Re: [R] collapsing a data frame

2007-10-12 Thread Chris Stubben
> On 10/12/07, Ben Bolker ufl.edu> wrote: > > > > Trying to find a quick/slick/easily interpretable way to > > collapse a data set. > > Another alternative for SQL fans is the sqldf package. I used the MySQL driver here since SQLite does not support standard deviation. sqldf("select BROOD,

Re: [R] collapsing a data frame

2007-10-12 Thread jim holtman
Here is one way. Not sure what you wanted done with some of the other variables, so I just chose the first one; you could do max/min: > z <- by(h, h$BROOD, function(x){ + # take first value of elements you don't want to change + data.frame(BROOD=x$BROOD[1], TICKS.mean=mean(x$TICKS), TICKS