powered by
Compute the weighted mean or weighted variance of a vector.
wtd.mean(x, weights = NULL, normwt = "ignored", na.rm = TRUE)
Numeric data vector
Numeric weights vector. Must be the same length as x
x
Only for wtd.var, if TRUE then weights are normalized for the weighted count to be the same as the non-weighted one
wtd.var
TRUE
if TRUE, delete NA values.
NA
If weights is NULL, then an uniform weighting is applied.
weights
NULL
mean,var, wtd.table and the survey package.
mean
var
wtd.table
survey
# 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 DataLab