Skip to contents

Small helper function to collapse factors using a Base R syntax

Usage

collapse_fct_levels(
  x = appdata$ECG$status,
  new_levels = list(old = "old", new = c("new", "updated")),
  warn_non_existent_levels = FALSE
)

Arguments

x

a character string or factor

new_levels

a named list of levels that need to be relabeled. They should be character values. If no names are provided, the first element will be chosen as the factor label.

warn_non_existent_levels

A logical, whether a warning should be given if levels are not existent.

Value

a factor with newly calculated levels

Examples

if (FALSE) { # \dontrun{
collapse_fct_levels(
x = LETTERS,
new_levels = list("A-C" = c("A", "B", "C"))
)
} # }