[R] weighted averages for two variables

Rui Barradas ruipbarradas at sapo.pt
Sat May 19 17:19:05 CEST 2012


Hello,

Thanks.
The revised 'by' I had posted works with me.
An alternative, more complicated, is using split/sapply.

sapply(split(allspecies, allspecies$Year), function(x)
         weighted.mean(x$Depth, x$CPUE))


Rui Barradas



More information about the R-help mailing list