Skip to contents

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.

Usage

var_desc(x, na.rm = FALSE)

Arguments

x

A numeric vector containing the data.

na.rm

A logical value indicating whether to remove missing values (NA) before computation. Default is FALSE.

Value

A numeric value representing the population variance of x.

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