collapse_cat {iNZightTools} | R Documentation |
Collapse data by values of a categorical variable
Description
Collapse values in a categorical variable into one defined level
Usage
collapse_cat(data, var, levels, new_level, name = NULL)
Arguments
data |
a dataframe to collapse |
var |
a string of the name of the categorical variable to collapse |
levels |
a character vector of the levels to be collapsed |
new_level |
a string for the new level |
name |
a name for the new variable |
Value
the original dataframe containing a new column of the collapsed variable with tidyverse code attached
Author(s)
Zhaoming Su
See Also
Examples
collapsed <- collapse_cat(iris,
var = "Species",
c("versicolor", "virginica"),
new_level = "V"
)
cat(code(collapsed))
tail(collapsed)
[Package iNZightTools version 2.0.1 Index]