Learn R Programming

SurveyStat (version 1.0.3)

standardize_categories: Standardize categorical values

Description

This function standardizes categorical variables by mapping values to standardized categories. Useful for consolidating different representations of the same category.

Usage

standardize_categories(data, col, mapping)

Value

A data.frame with standardized categories

Arguments

data

A data.frame containing survey data

col

Character string specifying column name to standardize

mapping

Named list or vector mapping old values to new values

Examples

Run this code
data <- data.frame(gender = c("M", "Male", "F", "Female", "m"))
mapping <- list("M" = "Male", "Male" = "Male", "F" = "Female", "Female" = "Female", "m" = "Male")
clean_data <- standardize_categories(data, "gender", mapping)

Run the code above in your browser using DataLab