Learn R Programming

textclean (version 0.3.0)

mgsub: Multiple gsub

Description

A wrapper for gsub that takes a vector of search terms and a vector or single value of replacements.

Usage

mgsub(x, pattern, replacement, leadspace = FALSE, trailspace = FALSE, fixed = TRUE, trim = TRUE, order.pattern = fixed, ...)

Arguments

x
A character vector.
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.
leadspace
logical. If TRUE inserts a leading space in the replacements.
trailspace
logical. If TRUE inserts a trailing space in the replacements.
fixed
logical. If TRUE, pattern is a string to be matched as is. Overrides all conflicting arguments.
trim
logical. If TRUE leading and trailing white spaces are removed and multiple white spaces are reduced to a single white space.
order.pattern
logical. If TRUE and fixed = TRUE, the pattern string is sorted by number of characters to prevent substrings replacing meta strings (e.g., pattern = c("the", "then") resorts to search for "then" first).
...
Additional arguments passed to gsub.

Value

mgsub - Returns a vector with the pattern replaced.

See Also

gsub

Examples

Run this code
mgsub(DATA$state, c("it's", "I'm"), c("it is", "I am"))
mgsub(DATA$state, "[[:punct:]]", "PUNC", fixed = FALSE)

Run the code above in your browser using DataLab