Function is a wrapper for gsub() which allows to replace more than one pattern.
Does not allow using regular expressions (internally, gsub(..., fixed = TRUE) is used).
Usage
gsubAll ( string, old, new)
Value
character vector with replaced patterns
Arguments
string
a character vector where matches are sought
old
character vector containing strings to be matched in the given character vector named string.
Can only contain unique entries.
new
a replacement for matched pattern
Details
Internally, the function calls gsub() repeatedly, beginning with the longest string in old.
String length is evaluated using nchar().
This is done to avoid repeated modifications if strings in old match each other.
### replace all numbers by wordstxt <- "1 example for 2 reasons in 4 seasons"gsubAll ( txt, old = as.character(1:4), new = c("one", "two", "three", "four"))