rc_char: Recodes exact matches in a character string

Description Usage Arguments Details Value Examples

View source: R/rc_char.R

Description

Finds values in x that are equivalent to values in from and substitutes them with corresponding values in to.

Usage

1
rc_char(x, from, to, warn = TRUE, default_NA = FALSE)

Arguments

x

A vector containing values that will be recoded based on from and to

from

A vector containing the values within x that will be recoded

to

A vector containing the corresponding value (or values) that from will be converted to

warn

If 'TRUE', a warning will be generated when values in 'x' are not contained in 'from

default_NA

If 'TRUE', rc_char will convert values from x not in from to NA

Details

If only a single value is included in to, then all values in x matching values in from will be changed to the single value in to. Otherwise, the lengths of from and to must be equal, and there can be no duplicated values in from.

Note that when anticipating output of rc_char, this function automatically converts all input arguments to character vectors in the first step.

Value

A character vector, derived from x, with 0 or more values substituted for new ones

Examples

1
2
3
4
x <- as.character(1:10)
from <- as.character(1:10)
to <- letters[1:10]
rc_char(x, from, to)

graggsd/sgcodebook documentation built on April 24, 2020, 5:39 a.m.