powered by
This function calculates the weighted total of a numeric variable. Useful for estimating population totals from survey data.
weighted_total(data, target_col, weight_col)
Numeric weighted total
A data.frame containing survey data
Character string specifying column name for target variable
Character string specifying column name containing weights
data <- data.frame(income = c(50000, 75000, 100000), weight = c(1000, 800, 1200)) total_income <- weighted_total(data, "income", "weight")
Run the code above in your browser using DataLab