
Compute the Coefficient of Variation (CV)
cv.RdCalculates the coefficient of variation for a numeric vector, defined as the ratio of the standard deviation to the mean. This provides a unitless measure of relative dispersion, allowing comparison of variability across variables or groups with different scales.
Value
A numeric value representing the coefficient of variation (CV). Returns `NA_real_` if the computation is not possible (e.g., all values are missing or the mean is zero).
Details
The function safely handles missing values and cases where the mean is zero (to avoid division by zero). If the input vector is empty or the mean equals zero, the function returns `NA_real_`.
Examples
x <- c(10, 12, 8, 15, NA)
cv(x)
#> [1] 0.2654292