#' 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
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.