Description Usage Arguments Value Examples
View source: R/dummify_factors.R
Takes a data frame and separates all columns containing categorical variables into dummy variables (one column per category). Unlike model.matrix(), does not exclude any categories from being converted into columns, and retains missing values.
1 | dummify_factors(df, dummify_characters = TRUE, max_levels = 52, sep = "__")
|
df |
A data frame containing the factors to be converted to dummies. |
dummify_characters |
Should |
max_levels |
The maximum number of levels that a categorical variable can have in order to be converted to dummies. This is to prevent converting variables such as respondent IDs or open-ended responses to dummy variables. Defaults to 52, which is slightly more than the number of U.S. states plus Washington, D.C. |
sep |
A character string that will go in between the original variable name and the
corresponding factor level in the output, e.g. VARIABLE__Category. Defaults to |
A copy of the original data frame where all factor variables have been replaced with dummies. Formatted as a tibble.
1 2 | test <- dummify_factors(dec13_excerpt)
head(test)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.