replace_values: Replace multiple unique elements with multiple unique...

Description Usage Arguments Value Examples

View source: R/replace.R

Description

Replace multiple unique elements with multiple unique replacements.

Usage

1
replace_values(vector, values, replacements, warn = TRUE)

Arguments

vector

Vector to make replacements in.

values

Values to be replaced (vector of same length as replacements).

replacements

Values to replace matches with (vector of same length as values).

warn

Logical indicating whether to issue a warning message if no element is replaced.

Value

Vector with elements in values replaced with the corresponding elements from replacements.

Every element in values will be searched for in vector. If it is found, it will be replaced in vector with the corresponding element of replacements. That is, if the 3rd element of values is found anywhere in vector, it will be replaced by the 3rd element of replacements.

Note that factors will be releveled with the replacement values and levels no longer present in the factor may be lost.

Examples

1
2
3
4
5
6
7
8
replace_values(
   vector = c("WA", "WY", "OR", "NY", "NY", "WA", "FL", "OR"),
   values = c("FL", "NY", "OR", "WA", "WY"),
   replacements = c("Florida", "New York", "Oregon", "Washington", "Wyoming"))
replace_values(
   vector = c("M", "F", "F", "M", "F", "M", "F", "M", "M", "M", "F", "F"),
   values = c("F", "M"),
   replacements = c("Female", "Male"))

seaaan/easieR documentation built on May 29, 2019, 4:23 p.m.