Learn R Programming

pollster (version 0.1.7)

wtd_mean: weighted mean

Description

wtd_mean returns the weighted mean of a variable. It's a tidy-compatible wrapper around stats::weighted.mean().

Usage

wtd_mean(df, variable, weight, na.rm = TRUE)

Value

a numeric value

Arguments

df

The data source

variable

the variable, it should be numeric

weight

The weighting variable

na.rm

Remove NA values or not, defaults to TRUE

Examples

Run this code
wtd_mean(illinois, age, weight)

library(dplyr)
illinois %>% wtd_mean(age, weight)

Run the code above in your browser using DataLab