# Load required packages and data
library(dplyr)
data(survey_data)
# Basic weighted IQR
survey_data %>% w_iqr(age, weights = sampling_weight)
# Multiple variables
survey_data %>% w_iqr(age, income, weights = sampling_weight)
# Grouped data
survey_data %>% group_by(region) %>% w_iqr(age, weights = sampling_weight)
# In summarise context
survey_data %>% summarise(iqr_age = w_iqr(age, weights = sampling_weight))
# Unweighted (for comparison)
survey_data %>% w_iqr(age)
Run the code above in your browser using DataLab