geomMean: geomMean

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/aveytoolkit_geomMean.R

Description

Calculate the geometric mean

Usage

1
geomMean(x, na.rm = FALSE, zero.propagate = TRUE)

Arguments

x

a vector of non-negative numeric values.

na.rm

(optional) whether to remove NA values before calculation. Default is FALSE

zero.propagate

(optional) logical specifying whether zeros should be progated such that if there are zeros in 'x' 0 should be returned.

Details

This function handles negative values by returning 'NaN' and zeros by returning '0' by default.

Value

the geometric mean of x

Author(s)

Paul McMurdie, Stefan Avey

References

http://stackoverflow.com/questions/2602583/geometric-mean-is-there-a-built-in

See Also

exp sum log

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
x <- 1:10
x2 <- c(x, NA)
x3 <- -5:5
x4 <- 0:4

geomMean(x)
mean(x)

geomMean(x2)
mean(x2)

geomMean(x2, na.rm = TRUE)
mean(x2, na.rm = TRUE)

## NaN because because x3 contains negative values ##
geomMean(x3)
mean(x3)

geomMean(x4)
geomMean(x4, zero.propagate = FALSE)
mean(x4)

stefanavey/aveytoolkit documentation built on March 5, 2020, 12:49 a.m.