Calculate the geometric mean

Usage

geomean(x, na.rm = TRUE)

Arguments

x
Vector of numbers
na.rm
Should NA values be omitted?

Value

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 checks for negative values, removes NA values per default and returns 0 if at least one element of the vector is 0.

Examples

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