| collapseLevels {iNZightTools} | R Documentation |
Collapse several values in a categorical variable into one level
collapseLevels(
.data,
var,
levels,
collapse = paste(levels, collapse = "_"),
name = sprintf("%s.coll", var)
)
.data |
a dataframe to collapse |
var |
a character of the name of the categorical variable to collapse |
levels |
a character vector of the levels to be collapsed |
collapse |
name of the newly created level |
name |
a name for the new variable |
the original dataframe containing a new column of the collapsed variable with tidyverse code attached
Owen Jin
collapsed <- collapseLevels(iris, var = "Species",
levels = c("setosa", "virginica"))
cat(code(collapsed))
head(collapsed)