Revision 0e640ebe37b48ee7398ce510677e75b37b969440 authored by Matthias Templ on 22 August 2016, 12:00:07 UTC, committed by cran-robot on 22 August 2016, 12:00:07 UTC
1 parent b0cf7e2
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])))
}
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...