labelled (version 2.2.1)

recode.haven_labelled: Recode values

Description

Extend recode method from haven to works with labelled vectors.

Usage

# S3 method for haven_labelled
recode(.x, ..., .default = NULL,
  .missing = NULL)

Arguments

.x

A vector to modify

...

Replacements. For character and factor .x, these should be named and replacement is based only on their name. For numeric .x, these can be named or not. If not named, the replacement is done based on position i.e. .x represents positions to look for in replacements. See examples.

When named, the argument names should be the current values to be replaced, and the argument values should be the new (replacement) values.

All replacements must be the same type, and must have either length one or the same length as .x.

These dots support tidy dots features.

.default

If supplied, all values not otherwise matched will be given this value. If not supplied and if the replacements are the same type as the original values in .x, unmatched values are not changed. If not supplied and if the replacements are not compatible, unmatched values are replaced with NA.

.default must be either length 1 or the same length as .x.

.missing

If supplied, any missing values in .x will be replaced by this value. Must be either length 1 or the same length as .x.

See Also

recode (dplyr)

Examples

Run this code
# NOT RUN {
x <- labelled(1:3, c(yes = 1, no = 2))
x
dplyr::recode(x, `3` = 2L)
# }

Run the code above in your browser using DataLab