multigsub | R Documentation |
multigsub
- A wrapper for gsub
that takes a vector
of search terms and a vector or single value of replacements.
sub_holder
- This function holds the place for particular character
values, allowing the user to manipulate the vector and then revert the place
holders back to the original values.
multigsub(
pattern,
replacement,
text.var,
leadspace = FALSE,
trailspace = FALSE,
fixed = TRUE,
trim = TRUE,
order.pattern = fixed,
...
)
mgsub(
pattern,
replacement,
text.var,
leadspace = FALSE,
trailspace = FALSE,
fixed = TRUE,
trim = TRUE,
order.pattern = fixed,
...
)
sub_holder(pattern, text.var, alpha.type = TRUE, ...)
pattern |
Character string to be matched in the given character vector. |
replacement |
Character string equal in length to pattern or of length one which are a replacement for matched pattern. |
text.var |
The text variable. |
leadspace |
logical. If |
trailspace |
logical. If |
fixed |
logical. If |
trim |
logical. If |
order.pattern |
logical. If |
... |
Additional arguments passed to |
alpha.type |
logical. If |
multigsub
- Returns a vector with the pattern replaced.
sub_holder
- Returns a list with the following:
output |
keyed place holder character vector |
unhold |
A function used to revert back to the original values |
The unhold
function for sub_holder
will only work on keys
that have not been disturbed by subsequent alterations. The key follows the
pattern of 'qdapplaceholder' followed by lower case letter keys followed by
'qdap'.
gsub
## Not run:
## ======================
## `mgsub` Function
## ======================
multigsub(c("it's", "I'm"), c("it is", "I am"), DATA$state)
mgsub(c("it's", "I'm"), c("it is", "I am"), DATA$state)
mgsub("[[:punct:]]", "PUNC", DATA$state, fixed = FALSE)
## ======================
## `sub_holder` Function
## ======================
## `alpha.type` as TRUE
(fake_dat <- paste(emoticon[1:11,2], DATA$state))
(m <- sub_holder(emoticon[,2], fake_dat))
m$unhold(strip(m$output))
# With Stemming
m$unhold(stemmer(strip(m$output), capitalize = FALSE))
## `alpha.type` as FALSE (numeric keys)
vowels <- LETTERS[c(1, 5, 9, 15, 21)]
(m2 <- sub_holder(vowels, toupper(DATA$state), alpha.type = FALSE))
m2$unhold(gsub("[^0-9]", "", m2$output))
mtabulate(strsplit(m2$unhold(gsub("[^0-9]", "", m2$output)), ""))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.