powered by
This function creates a frequency table for a categorical variable, optionally incorporating survey weights.
frequency_table(data, col, weight_col = NULL)
A data.frame with frequency statistics
A data.frame containing survey data
Character string specifying column name for categorical variable
Character string specifying column name containing weights (optional)
data <- data.frame(gender = c("M", "F", "M", "F"), weight = c(1, 1.2, 0.8, 1.1)) freq_table <- frequency_table(data, "gender") weighted_freq <- frequency_table(data, "gender", "weight")
Run the code above in your browser using DataLab