DescTools (version 0.99.13)

Hmean: Harmonic mean

Description

Calculates the harmonic mean of a vector x.

Usage

Hmean(x, na.rm = FALSE)

Arguments

x
a positive numeric vector. An object which is not a vector is coerced (if possible) by as.vector.
na.rm
logical, indicating whether NA values should be stripped before the computation proceeds. Defaults to FALSE.

Value

  • a numeric value.

Details

If any argument is negative, then the result will be NA. If any argument is zero, then the harmonic mean is zero. Otherwise, the harmonic mean is the reciprocal of the arithmetic mean of the reciprocals of the values. Use sapply to calculate the measures from data frame, resp. from a matrix.

See Also

Gmean

Examples

Run this code
x <- runif(5)
Hmean(x)

m <- matrix(runif(50), nrow = 10)
apply(m, 2, Hmean)

sapply(as.data.frame(m), Hmean)

Run the code above in your browser using DataCamp Workspace