questionr (version 0.6.3)

wtd.mean: Weighted mean and variance of a vector

Description

Compute the weighted mean or weighted variance of a vector.

Usage

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

Arguments

x

Numeric data vector

weights

Numeric weights vector. Must be the same length as x

normwt

Only for wtd.var, if TRUE then weights are normalized for the weighted count to be the same as the non-weighted one

na.rm

if TRUE, delete NA values.

Details

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

See Also

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

Examples

Run this code
# NOT RUN {
data(hdv2003)
mean(hdv2003$age)
wtd.mean(hdv2003$age, weights=hdv2003$poids)
var(hdv2003$age)
wtd.var(hdv2003$age, weights=hdv2003$poids)
# }

Run the code above in your browser using DataCamp Workspace