#' This is a quick and dirty harmonic mean calculation
#'
#' This estimates the harmonic mean.
#' @param x a vector of values
#' @return The harmonic mean
#' @export
#' @examples
#' x <- c(1,2,3,4,5)
#' harmonic_mean(x)
#' x <- c(1,2,3,4,5,0)
#' harmonic_mean(x)
harmonic_mean <- function(x) {
if( any(x==0) ) {
warning("Estimating harmonic mean with a zero, this is an undefined operation.")
}
return( 1/mean(1/x) )
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.