mgsub {kutils}R Documentation

apply a vector of replacements, one after the other.

Description

This is multi-gsub. Use it when it is necessary to process many patterns and replacements in a given order on a vector.

Usage

mgsub(pattern, replacement, x, ...)

Arguments

pattern

vector of values to be replaced. A vector filled with patterns as documented in the gsub pattern argument

replacement

vector of replacements, otherwise same as gsub. Length of replacement must be either 1 or same as pattern, otherwise an error results.

x

the vector in which elements are to be replaced, same as gsub

...

Additional arguments to be passed to gsub

Value

vector with pattern replaced by replacement

Author(s)

Jared Harpole <jared.harpole@gmail.com> and Paul Johnson <pauljohn@ku.edu>

Examples

x <- c("Tom", "Jerry", "Elmer", "Bugs")
pattern <- c("Tom", "Bugs")
replacement <- c("Thomas", "Bugs Bunny")
(y <- mgsub(pattern, replacement, x))
x[1] <- "tom"
(y <- mgsub(pattern, replacement, x, ignore.case = TRUE))
(y <- mgsub(c("Elmer", "Bugs"), c("Looney Characters"), x, ignore.case = TRUE))

[Package kutils version 1.73 Index]