[R] tapply for function taking of >1 argument?

hadley wickham h.wickham at gmail.com
Wed Feb 3 18:43:04 CET 2010


On Wed, Feb 3, 2010 at 11:06 AM, David Freedman <3.14david at gmail.com> wrote:
>
> also,
>
> library(plyr)
> ddply(d,~grp,function(df) weighted.mean(df$x,df$w))

Or

ddply(d, "grp", summarise, mean = weighted.mean(x, w))

which is convenient if you want more than one output

Hadley



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



More information about the R-help mailing list