chr.gsub | R Documentation |
This function is a multiple global string replacement wrapper that allows access to multiple methods of specifying matches and replacements.
chr.gsub(pattern, replacement, x, recycle = FALSE, ...)
pattern |
a character vector with character strings to be matched. |
replacement |
a character vector equal in length to |
x |
a character vector where matches and replacements are sought. |
recycle |
logical: if |
... |
additional arguments to pass to the |
Return a character vector of the same length and with the same attributes as
x
(after possible coercion to character).
This function was adapted from the mgsub()
function in the mgsub
package by Mark Ewing (2019).
Mark Ewing
Mark Ewing (2019). mgsub: Safe, Multiple, Simultaneous String Substitution. R package version 1.7.1. https://CRAN.R-project.org/package=mgsub
chr.omit
, chr.trim
string <- c("hey ho, let's go!")
chr.gsub(c("hey", "ho"), c("ho", "hey"), string)
string <- "they don't understand the value of what they seek."
chr.gsub(c("the", "they"), c("a", "we"), string)
string <- c("hey ho, let's go!")
chr.gsub(c("hey", "ho"), "yo", string, recycle = TRUE)
string <- "Dopazamine is not the same as dopachloride or dopastriamine, yet is still fake."
chr.gsub(c("[Dd]opa([^ ]*?mine)","fake"), c("Meta\\1","real"), string)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.