collapse_cat | R Documentation |
Collapse values in a categorical variable into one defined level
collapse_cat(data, var, levels, new_level, name = NULL)
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 |
the original dataframe containing a new column of the collapsed variable with tidyverse code attached
Zhaoming Su
code
collapsed <- collapse_cat(iris,
var = "Species",
c("versicolor", "virginica"),
new_level = "V"
)
cat(code(collapsed))
tail(collapsed)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.