The geometric mean is the nth root of n products or e to the mean log of x. Useful for describing non-normal, i.e., geometric distributions.

geometric.mean(x,na.rm=TRUE)

Arguments

x

a vector or data.frame

na.rm

remove NA values before processing

Details

Useful for teaching how to write functions, also useful for showing the different ways of estimating central tendency.

Value

geometric mean(s) of x or x.df.

Author

William Revelle

Note

Not particularly useful if there are elements that are <= 0.

See also

Examples


x <- seq(1,5)
x2 <- x^2
x2[2] <- NA
X <- data.frame(x,x2)
geometric.mean(x)
#> [1] 2.605171
geometric.mean(x2)
#> [1] 7.745967
geometric.mean(X)
#>        x       x2 
#> 2.605171 7.745967 
geometric.mean(X,na.rm=FALSE)
#>        x       x2 
#> 2.605171       NA