Learn R Programming

SurveyStat (version 1.0.3)

frequency_table: Generate frequency table for categorical variable

Description

This function creates a frequency table for a categorical variable, optionally incorporating survey weights.

Usage

frequency_table(data, col, weight_col = NULL)

Value

A data.frame with frequency statistics

Arguments

data

A data.frame containing survey data

col

Character string specifying column name for 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"), 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