[R] "by" question

hadley wickham h.wickham at gmail.com
Wed Jun 24 20:48:52 CEST 2009


You might also want to look at the plyr package,
http://had.co.nz/plyr.  In particular, ddply + transform makes these
tasks very easy.

library(plyr)
ddply(mtcars, "cyl", transform, pos = seq_along(cyl), mpg_avg = mean(mpg))

Hadley

On Wed, Jun 24, 2009 at 11:48 AM, David
Hugh-Jones<davidhughjones at gmail.com> wrote:
> That seems to work. I should add that to make "ave" work like "by" one can
> do:
>
> mydata$newvar <- ave(1:nrow(mydata), mydata$some_factor, FUN= function (x) {
>  x <- ds[x,]
> # ... etc...
> })
>
> Thanks!
> David
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>



-- 
http://had.co.nz/




More information about the R-help mailing list