Learn R Programming

SurveyStat (version 1.0.3)

cross_tabulation: Generate cross-tabulation table with chi-square test

Description

This function creates a cross-tabulation between two categorical variables and performs a chi-square test of independence. Can incorporate survey weights.

Usage

cross_tabulation(data, col1, col2, weight_col = NULL)

Value

A list containing cross-tabulation and chi-square test results

Arguments

data

A data.frame containing survey data

col1

Character string specifying first categorical variable

col2

Character string specifying second categorical variable

weight_col

Character string specifying column name containing weights (optional)

Examples

Run this code
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