This function computes the percent coefficient of variation of the values in x. If na.rm is TRUE then missing values are removed before computation proceeds.
Arguments
- x
a numeric vector with untransformed data
- na.rm
logical, if TRUE then NA values are stripped from x before computation takes place
- use_robust_cv
logical, if TRUE the robust coefficient of variation (scaled median absolute deviation / median) is computed instead of the standard CV (SD / mean)
- min_n
integer, the minimum number of observations (non-missing ones when
na.rm = TRUE) required to return a CV. Fewer thanmin_nvalues returnNA_real_. The default (1) is a no-op, sincesd()/mad()already returnNAfor fewer than two values.
Value
a numeric value. If the mean (or the median, for robust CV) is zero, or x is not numeric, NA_real_ is returned
Examples
cv(c(5, 6, 3, 4, 5, NA), na.rm = TRUE)
#> [1] 24.78642