dummify_scale: Convert categorical variables to dummy variables

dummify_scaleR Documentation

Convert categorical variables to dummy variables

Description

This function transforms specified categorical variables into dummy variables. Each level of the categorical variable is represented by a new dummy variable. Missing values are retained. These new dummy variables are appended to the original data frame. This function does not allow specifying new column names for the dummy variables. Instead, it follows a consistent naming pattern: the new dummy variables are named using the original variable name with the category value appended. For example, if a categorical variable named "autonomy" with levels "low", "medium", "high" is dummified, the new dummy variables will be named "autonomy_low", "autonomy_medium", "autonomy_high".

Usage

dummify_scale(data, ..., overwrite = FALSE)

Arguments

data

A tibble or a tdcmm model.

...

Categorical variables to be transformed into dummy variables. Category names will be automatically appended to the newly created dummy variables.

overwrite

Logical. If TRUE, it overwrites the original variable(s) with the dummy variables. If FALSE (default), new variables are created.

Value

A tdcmm model with the dummy variables appended.

See Also

Other scaling: categorize_scale(), center_scale(), minmax_scale(), recode_cat_scale(), reverse_scale(), setna_scale(), z_scale()

Examples

WoJ %>% dplyr::select(temp_contract) %>% dummify_scale(temp_contract)
WoJ %>% categorize_scale(autonomy_emphasis, breaks = c(2, 3),
labels = c('low', 'medium', 'high')) %>%
dummify_scale(autonomy_emphasis_cat) %>% dplyr::select(starts_with('autonomy_emphasis'))

joon-e/tidycomm documentation built on Feb. 24, 2024, 8:58 a.m.