R/cv.R

#' coefficient of Variation
#'
#' Calculate the coefficient of variation of a numeric vector.
#' @param x Numeric vector
#' @export
#' @return Numeric
#' @examples
#' CV(x)

CV <- function(x,
               na.rm = F){
  # check for pos and neg values
  if (-1 %in% sign(x) && 1 %in% sign(x)){
    warning("'x' contains both positive and negative values, which results in an incorrect response.",
            call. = F)
  }
  ( sd(x, na.rm = na.rm) / mean(x, na.rm = na.rm) ) * 100
}
ssaxe-usgs/saxey documentation built on May 25, 2019, 5:02 a.m.