collapse_cat: Collapse data by values of a categorical variable

View source: R/mutate.R

collapse_catR 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

code

Examples

collapsed <- collapse_cat(iris,
    var = "Species",
    c("versicolor", "virginica"),
    new_level = "V"
)
cat(code(collapsed))
tail(collapsed)


iNZightTools documentation built on Oct. 12, 2023, 5:06 p.m.