geomean: Geometric mean of a vector

View source: R/specific_calculations.R

geomeanR Documentation

Geometric mean of a vector

Description

The geometric mean is useful when your values are imbalanced by outliers. Daniel McNichol wrote a very approachable article about this topic.

Usage

geomean(x, na.rm = TRUE)

Arguments

x

(Numeric) A vector.

na.rm

(Logical) If TRUE, NAs will be silently removed.

Details

This function is by Paul McMurdie and is "vectorized, zero- and NA-tolerant ... checks for any negative values, and returns a more informative and appropriate NaN respecting that geometric mean is not defined for negative values (but is for zeros)."

Value

A numeric vector of length 1.

Authors

Source

https://stackoverflow.com/a/25555105/5578429

Examples

vec <- c(1, 3, 9, 27, 81, 243, 729)

mean(vec)
#> [1] 156.1429

geomean(vec)
#> [1] 27


DesiQuintans/desiderata documentation built on April 9, 2023, 5:43 a.m.