powered by
Combine specified categorical variables by concatenating their values into one character, and returns the result along with tidyverse code used to generate it.
combineCatVars( .data, vars, sep = ".", name = paste(vars, collapse = sep), keep_empty = FALSE )
original dataframe containing a new column of the renamed categorical variable with tidyverse code attached
a dataframe with the columns to be combined
a character vector of the categorical variables to be combined
the separator to combine the values of the variables in var by. "." by default
var
a name for the new variable
logical, if FALSE empty level combinations are removed from the factor
FALSE
Owen Jin
When either variable is NA, the result is NA.
combined <- combineCatVars(warpbreaks, vars = c("wool", "tension"), sep = "_") cat(code(combined)) head(combined)
Run the code above in your browser using DataLab