weighted mean by week
Thanks a lot, David. Indeed, it's much shorter. Unfortunately, in my real task I am dozens and dozens of variables like var1 and var2 so that manually specifying things like in "m1=weighted.mean(var1,myweight)" would take a lot of code and a very long time. Dimitri
On Tue, Jul 17, 2012 at 6:34 PM, David Freedman <dxf1 at cdc.gov> wrote:
The plyr package is very helpful for this: library(plyr) ddply(x ,.(myweek), summarize, m1=weighted.mean(var1,myweight), m2=weighted.mean(var2,myweight)) -- View this message in context: http://r.789695.n4.nabble.com/weighted-mean-by-week-tp4636814p4636816.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
Dimitri Liakhovitski marketfusionanalytics.com