powered by
Combine chosen variables of any class by concatenating them into one factor variable, and returns the result along with tidyverse code used to generate it.
combine_vars( data, vars, sep = ":", name = NULL, keep_empty = FALSE, keep_na = TRUE )
original dataframe containing new columns of the new categorical variable with tidyverse code attached
a dataframe with the columns to be combined
a character vector of the variables to be combined
a character string to separate the levels
a name for the new variable
logical, if FALSE empty level combinations are removed from the factor
FALSE
logical, if TRUE the <NA> in the factors or NA in the characters will turn in a level "(Missing)"; otherwise, the resulting entries will return <NA>
TRUE
<NA>
NA
"(Missing)"
Owen Jin, Zhaoming Su
combined <- combine_vars(warpbreaks, vars = c("wool", "tension"), sep = "_") cat(code(combined)) head(combined)
Run the code above in your browser using DataLab