Learn R Programming

tern (version 0.9.7)

fct_collapse_only: Collapse factor levels and keep only those new group levels

Description

[Stable]

This collapses levels and only keeps those new group levels, in the order provided. The returned factor has levels in the order given, with the possible missing level last (this will only be included if there are missing values).

Usage

fct_collapse_only(.f, ..., .na_level = "")

Value

A modified factor with collapsed levels. Values and levels which are not included in the given character vector input will be set to the missing level .na_level.

Arguments

.f

(factor or character)
original vector.

...

(named character)
levels in each vector provided will be collapsed into the new level given by the respective name.

.na_level

(string)
which level to use for other levels, which should be missing in the new factor. Note that this level must not be contained in the new levels specified in ....

See Also

Examples

Run this code
fct_collapse_only(factor(c("a", "b", "c", "d")), TRT = "b", CTRL = c("c", "d"))

Run the code above in your browser using DataLab