Weighted harmonic mean of a vector. NA
are skipped by default.
Arguments
- x
A numeric vector of positive values.
- w
A vector of weights, which should have length equal to
length(x)
. Weights are relative and will be re-scaled to sum to 1. Ifw
is not specified, defaults to equal weights.
Examples
# a vector of values
x <- 1:10
# a vector of weights
w <- runif(10)
# weighted harmonic mean
a_hmean(x,w)
#> [1] 2.879339