https://github.com/cran/robCompositions
Raw File
Tip revision: 0e640ebe37b48ee7398ce510677e75b37b969440 authored by Matthias Templ on 22 August 2016, 12:00:07 UTC
version 2.0.2
Tip revision: 0e640eb
gm.R
#' geometric mean
#' 
#' This function calculates the geometric mean.
#' 
#' Calculates the geometric mean of all positive entries of a vector.
#' 
#' @param x A numeric vector.
#' @return The geometric mean.
#' @author Matthias Templ
#' @keywords math
#' @export
#' @examples
#' 
#' gm(runif(100))
#' 
gm <- function (x) {
	if(!is.numeric(x)) stop("x has to be a vector of class numeric")
	if (any(na.omit(x == 0)))
		0
	else exp(mean(log(unclass(x)[is.finite(x) & x > 0])))
}
back to top