Skip to content

weighted averages for two variables

2 messages · Rui Barradas, mpostje

#
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