Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

harmonic_mean

Harmonic Mean


Description

The harmonic mean is the reciprocal of the arithmetic mean of the reciprocals of the input values. Common uses include computing the mean of ratios, for instance the average P/E ratio in a portfolio. Also it is the correct mean for averaging speeds weighted for distance.

Usage

harmonic_mean(x, weights = NULL, na.rm = c(TRUE, FALSE))

Arguments

x

A vector of values to take the harmonic mean for

weights

Optional vector of weights.

na.rm

remove NAs (default = TRUE).

Value

  • Harmonic mean of x

References

See Also

Examples

# Harmonic means are suitable for ratios
tmp = c(33/1, 23/1)
harmonic_mean(tmp)

geometric_mean(tmp)
mean(tmp)

# Example with weights
harmonic_mean(c(33/1, 23/1), weights= c(.2, .8))
# If Jack travels outbound at 1 mph, and returns at 10 miles an hour, what is his average speed?
harmonic_mean(c(1,10)) # 1.81 mph

umx

Structural Equation Modeling and Twin Modeling in R

v4.10.10
GPL-3
Authors
Timothy C. Bates [aut, cre] (<https://orcid.org/0000-0002-1153-9007>), Gillespie Nathan [wit], Michael Zakharin [wit], Brenton Wiernik [ctb], Joshua N. Pritikin [ctb], Michael C. Neale [ctb], Hermine Maes [ctb]
Initial release
2021-11-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.