mean_geom: Returns the geometric mean of a vector

View source: R/stat_funcs.R

mean_geomR Documentation

Returns the geometric mean of a vector

Description

Calculates the geometric mean of a vector, returning a single value. The geometric mean, like the mean and the median, is an indication of the central tendancy of a set of numbers. The geometric mean is the nth root of the product of n numbers. For instance, the geometric mean of 2 and 8 is sqrt(2 * 8) = 4. The geometric mean is useful when computing the central tendency of measures that have different ranges. For instance, when computing a single "figure of merit" from differentrating scales that have ranges 0 to 5 and 0 to 100.

Usage

mean_geom(x, na.rm = TRUE)

Arguments

x

A numeric or integer vector

na.rm

a boolean indicating, if TRUE, removes NA values before calculating the mean

Details

The geometric mean is only defined for positive numbers, and mean_geom first removes any negative numbers. For speed, mean_geom computes the log of each term, sums the logs, then computes the exponent of the sum.

Value

The geometric mean of the vector x, or NULL with a warning if the geometric mean cannot be calculated


tomhopper/numbr documentation built on Nov. 5, 2022, 11:35 p.m.