# Load required packages and data
library(dplyr)
data(survey_data)
# Basic weighted mode (most frequent value)
survey_data %>% w_modus(gender, weights = sampling_weight)
# Multiple variables (works best with categorical/discrete data)
survey_data %>% w_modus(gender, region, weights = sampling_weight)
# Grouped data
survey_data %>% group_by(region) %>% w_modus(gender, weights = sampling_weight)
# In summarise context
survey_data %>% summarise(mode_gender = w_modus(gender, weights = sampling_weight))
# Unweighted (for comparison)
survey_data %>% w_modus(gender)
Run the code above in your browser using DataLab