wtd.mean: Weighted mean and variance of a vector

wtd.meanR Documentation

Weighted mean and variance of a vector

Description

Compute the weighted mean or weighted variance of a vector. Exact copies of Hmisc functions.

Usage

wtd.mean(x, weights = NULL, na.rm = TRUE)

Arguments

x

Numeric data vector

weights

Numeric weights vector. Must be the same length as x

na.rm

if TRUE, delete NA values.

Details

If weights is NULL, then an uniform weighting is applied.

Author(s)

These functions are exact copies of the wtd.mean and wtd.var function from the wtd.stats package. They have been created by Frank Harrell, Department of Biostatistics, Vanderbilt University School of Medicine, <f.harrell@vanderbilt.edu>.

See Also

mean,var, wtd.table and the survey package.

Examples

data(hdv2003)
mean(hdv2003$age)
wtd.mean(hdv2003$age, weights=hdv2003$poids)

questionr documentation built on Feb. 16, 2023, 10:14 p.m.