combine_vars {iNZightTools} | R Documentation |
Combine variables into one categorical variable
Description
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.
Usage
combine_vars(
data,
vars,
sep = ":",
name = NULL,
keep_empty = FALSE,
keep_na = TRUE
)
Arguments
data |
a dataframe with the columns to be combined |
vars |
a character vector of the variables to be combined |
sep |
a character string to separate the levels |
name |
a name for the new variable |
keep_empty |
logical, if |
keep_na |
logical, if |
Value
original dataframe containing new columns of the new categorical variable with tidyverse code attached
Author(s)
Owen Jin, Zhaoming Su
Examples
combined <- combine_vars(warpbreaks, vars = c("wool", "tension"), sep = "_")
cat(code(combined))
head(combined)
[Package iNZightTools version 2.0.1 Index]