[R] weighted averages for two variables
Rui Barradas
ruipbarradas at sapo.pt
Sat May 19 16:36:17 CEST 2012
Hello,
Post a data example, it will give us something to work on, and give you
better answers.
dput( head(allspecies, 20) )
Then copy the output of this and paste it in your post.
As for your problem, considering it's description, and untested (no
data), maybe
result <- by(allspecies, allspecies$Year, function(x)
weighted.mean(x$Depth, x$CPUE))
Also, note that I've renamed the result, 'data' is an R function.
Hope this helps,
Rui Barradas
More information about the R-help
mailing list