powered by
wtd_mean returns the weighted mean of a variable. It's a tidy-compatible wrapper around stats::weighted.mean().
wtd_mean
wtd_mean(df, variable, weight)
a numeric value
The data source
the variable, it should be numeric
The weighting variable
wtd_mean(illinois, age, weight) library(dplyr) illinois %>% wtd_mean(age, weight)
Run the code above in your browser using DataLab