geomean: Calculate the geometric mean

View source: R/geomean.R

geomeanR Documentation

Calculate the geometric mean

Description

Based on some posts in a thread on Stackoverflow http://stackoverflow.com/questions/2602583/geometric-mean-is-there-a-built-in This function returns NA if NA values are present and na.rm = FALSE (default). If negative values are present, it gives an error message. If at least one element of the vector is 0, it returns 0.

Usage

geomean(x, na.rm = FALSE)

Arguments

x

Vector of numbers

na.rm

Should NA values be omitted?

Value

The geometric mean

Author(s)

Johannes Ranke

Examples

geomean(c(1, 3, 9))
geomean(c(1, 3, NA, 9))
## Not run: geomean(c(1, -3, 9)) # returns an error

jranke/pfm documentation built on Dec. 17, 2024, 12:01 p.m.