Returns the weighted mean of a numeric vector.
In contrast to stats::weighted.mean()
, w
does not need to be specified.
weighted_mean(x, w = NULL, ...)
Numeric vector.
Optional vector of non-negative case weights.
Further arguments passed to mean()
or stats::weighted.mean()
.
A length-one numeric vector.
weighted_mean(1:10)
#> [1] 5.5
weighted_mean(1:10, w = NULL)
#> [1] 5.5
weighted_mean(1:10, w = 1:10)
#> [1] 7