library(dplyr)
data(survey_data)
# Create dummies and append to data (default)
data <- to_dummy(survey_data, gender)
# Use labels for column names
data <- to_dummy(survey_data, gender, suffix = "label")
# n-1 dummies with reference category
data <- to_dummy(survey_data, gender, ref = 1)
# Multiple variables
data <- to_dummy(survey_data, gender, education, suffix = "label")
# Return only the dummy columns (without original data)
dummies <- to_dummy(survey_data, gender, append = FALSE)
Run the code above in your browser using DataLab