This function calculates the population variance of a numeric vector.
Unlike the default var()
function in R, which computes the sample variance,
this function adjusts the calculation to use n instead of n-1 in the denominator.
See also
sd_desc
for computing the population standard deviation.
Examples
data <- c(10, 20, 30, 40, 50, NA)
var_desc(data) # Compute variance including NA (returns NA)
#> [1] NA
var_desc(data, na.rm = TRUE) # Compute variance ignoring NA
#> [1] 200