'tidymodels recipes: can I use step_dummy() to one-hot encode the categorical variabes *except* booleans which only needs 1 dummy?

If a categorical variable has more than 2 values (like marital status= single/married/widowed/separated/divorced), then I need to create N dummies, one for each of the possible levels. This is done using step_dummy(one_hot = TRUE).

However, if the category is binary (pokemon_fan = "yes"/"no") then I only need to create a single dummy called "pokemon_fan_yes". This is done using step_dummy(one_hot = FALSE).

Is it possible for step_dummy to count the number of levels and proceed differently depending on that number?

thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source