Hi R experts,
I need know how calculate a weighted mean by group in a data frame. I have
tried with aggragate() function:
data.frame(x=c(15,12,3,10,10),g=c(1,1,1,2,2,3,3),w=c(2,3,1,5,5,2,5)) -> d
aggregate(d$x,by=list(d$g),weighted.mean,w=d$w)
Generating the following error:
Error en FUN(X[[1L]], ...) : 'x' and 'w' must have the same length
Thanks in advance
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.