replace_match: Replace the value that exactly matches the pattern with a...

View source: R/repcale_match.R

replace_matchR Documentation

Replace the value that exactly matches the pattern with a replacement

Description

Function to replace a value that exactly matches a pattern with a replacement. Given a vector of equal length for pattern and replacement, the first value of pattern is interpreted as replacing the first value of replacement. See the argument descriptions for details.

Usage

replace_match(x, pattern, replacement, nomatch)

Arguments

x

Vector of values to be converted.

pattern

The value of the pattern to be converted or a vector containing it. If given in a vector of two or more lengths, it is determined that it should be replaced by a value equal to the position of each of the values given in the replacement argument.

replacement

The value of the replacement to be converted or a vector containing it. If given in a vector of two or more lengths, it is determined that it should be replaced by a value equal to the position of each of the values given in the pattern argument.

nomatch

Specifies the value to return if there is no matching pattern and replacement value. If no value is specified, the original x value is returned.

Examples

values <- c("HOKKAIDOU", "hokkaidou", "TOUHOKU", "touhoku")
pattern <- c("hokkaidou", "touhoku")
replacement <- c("HOKKAIDOU", "TOUHOKU")
replace_match(values, pattern, replacement)
replace_match(values, pattern, replacement, nomatch = NA)

indenkun/infun documentation built on April 17, 2025, 2:52 p.m.