Description Usage Arguments Details Value TODO See Also Examples
Dummy coding expands a polytomous categorical factor into several indicator variables, each of which is logical (Boolean, TRUE/FALSE).
1 | dummy_code(.data)
|
.data |
data frame |
The one-hot contrast expands a factor with L
levels into L
indicator variables. The result is not a full-rank parameterisation,
however it avoids needing to select a reference level.
Ordinal (ordered categorical) and dichotomous (only 2 levels) variables are not modified; nor are non-factors (numeric, logical, etc.).
Note that the number of levels is determined from the unique values in the actual data, rather than the factor levels.
The new indicator variables are appended to the end of the variable list, and the original factors are removed.
data frame with selected factors converted to logical dummy variables
if .data has only one factor, it is renamed "data"
Other data munging:
drop_nzv()
,
ord_collapse()
1 2 | library(dplyr)
mtcars %>% mutate(across(c("cyl", "gear"), as.factor)) %>% dummy_code()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.