Skip to contents

Calculate the weighted harmonic mean

Usage

weight.harm.mean(x, weights = NULL, na.rm = FALSE, ...)

Arguments

x

an object containing a set of observations whose weighted harmonic mean is to be computed

weights

a numerical vector of weights the same length as x

na.rm

logical by default set to FALSE. To remove NAs set argument to TRUE

...

additional arguments passed to or from other methods

Value

a numeric vector or length equal or greater than 1L

Examples

d <- rlnorm(60,1,1.4)
w <- rlnorm(60,2,3.23)
weight.harm.mean(d,w)
#> [1] 2.093143

x <- matrix(rlnorm(60,1,1.4), ncol = 4)
w <- matrix(rlnorm(60,1,1), ncol = 4)
mapply(weight.harm.mean, as.data.frame(x),as.data.frame(w))
#>        V1        V2        V3        V4 
#> 0.6187375 0.9686720 1.0740613 1.0661302