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 |
replacement |
vector of replacements, otherwise same as
|
x |
the vector in which elements are to be replaced, same as
|
... |
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]