R/calc_geom_mean.R

Defines functions calc_geom_mean

#' Calculate the geometric mean
#' @param values a numeric vector of values
#' @return returns the geometric mean if all values are at least zero,
#'   else returns NA
#' @author Richèl J.C. Bilderbeek
#' @noRd
calc_geom_mean <- function(values) {
  if (any(values < 0.0)) return(NA)
  exp(mean(log(values)))
}
ropensci/tracerer documentation built on March 12, 2019, 8:30 p.m.