Skip to content
Prev 74881 / 398502 Next

using weighted.mean with tapply()

I am trying to calculate the weighted mean for a of 10 deciles and I
get an error:
Error in FUN(X[[1]], ...) : 'x' and 'w' must have the same length

All three of my inputs have the same length, as shown below, and the
weighted.mean calculation works by itself, just not in tapply()
[1] 1853
[1] 1853
[1] 1853
[1] -0.04475397
weighted.mean(mat$trt1m, w=mat$mcap)
[1] -0.04819243
I am probably making a simple error in how I pass the optional
parameter w.  Any help would be greatly appreciated.