Re: [R] lapply and aggregate function

2009-02-03 Thread hadley wickham
> # Second > set.seed(321) > myD <- data.frame( Light = sample(LETTERS[1:2], 10, replace=T), >value=rnorm(20) ) > > w1 <- tapply(myD$value, myD$Light, mean) > w1 > # > w1 > # A B > # 0.4753412 -0.2108387 > > myfun <- function(x) (myD$value > w1[x] & myD$value <

Re: [R] lapply and aggregate function

2009-02-03 Thread David Freedman
You might want to look at the doBy package For (1), you could use summaryBy(value~Light+Feed,data=myD, FUN=mean) and for (2), the transformBy function would be helpful David Freedman Patrick Hausmann wrote: > > Dear list, > > I have two things I am struggling... > > # First > set.seed(123)

Re: [R] lapply and aggregate function

2009-02-03 Thread ONKELINX, Thierry
Have a look at cast() form the reshape package. library(reshape) set.seed(123) myD <- data.frame( Light = sample(LETTERS[1:2], 10, replace=T), Feed = sample(letters[1:5], 20, replace=T), value=rnorm(20) ) cast(myD, Light ~ ., fun = mean) cast(myD, Feed ~ ., fun = m