df <- tidytable(
col1 = c("a", "b", "c", NA),
col2 = as.factor(c("a", "b", NA, "d")),
var1 = rnorm(4, 0, 1)
)
# Automatically does all character/factor columns
df %>%
get_dummies.()
# Can select one column
df %>%
get_dummies.(col1)
# Can select one or multiple columns in a vector of unquoted column names
df %>%
get_dummies.(c(col1, col2))
# Can drop certain columns using
df %>%
get_dummies.(c(where(is.character), -col2))
df %>%
get_dummies.(prefix_sep = ".", drop_first = TRUE)
df %>%
get_dummies.(c(col1, col2), dummify_na = FALSE)
Run the code above in your browser using DataLab