Learn R Programming

statisfactory (version 1.0.4)

geoMean: Geometric mean

Description

Geometric mean, with optional removal of NA's and propagation of zeros.

Usage

geoMean(x, prop0 = FALSE, na.rm = TRUE)

Value

Numeric.

Arguments

x

Numeric list.

prop0

Logical, if FALSE (default) then if any value in x equals 0 then the output will be zero. If TRUE, then zero values will be removed before calculation of the geometric mean.

na.rm

Logical, if TRUE then remove NA values first.

Details

Adapted from Paul McMurdie on StackOverflow.

Examples

Run this code

x <- seq(0.01, 1, by=0.01)
mean(x)
geoMean(x)
x <- seq(0, 1, by=0.01)
mean(x)
geoMean(x)
geoMean(x, prop0=TRUE)

Run the code above in your browser using DataLab