powered by
This function creates a cross-tabulation between two categorical variables and performs a chi-square test of independence. Can incorporate survey weights.
cross_tabulation(data, col1, col2, weight_col = NULL)
A list containing cross-tabulation and chi-square test results
A data.frame containing survey data
Character string specifying first categorical variable
Character string specifying second categorical variable
Character string specifying column name containing weights (optional)
data <- data.frame(gender = c("M", "F", "M", "F"), education = c("HS", "College", "HS", "College")) cross_tab <- cross_tabulation(data, "gender", "education")
Run the code above in your browser using DataLab