R/cv.R

Defines functions cv

Documented in cv

#' Calculate the coefficient of variation
#'
#' Calculate the coefficient of variation a vector of numbers, as \code{SD(x) / mean(x)}.
#' This function does NOT calculate percent CV - that requires multiplying the returned
#' values by 100.
#' @param x numeric vector or matrix
#' @param na.rm logical. Should missing values be removed?
#' @importFrom stats sd
#' @export
#' @return a single numeric value
#' @usage cv(x, na.rm = FALSE)
cv <- function(x, na.rm = FALSE) {
  sd(x, na.rm = na.rm) / mean(x, na.rm = na.rm)
}
mjdufort/miscHelpers documentation built on Feb. 4, 2024, 7:44 p.m.