%regex=% {roperators} | R Documentation |
Modify existing object by regular expression
Description
This takes two arguments just like gsub
- a patterns and a replacement.
It will only overwrite the parts of any character where the pattern is matched with the second argument.
If you want to overwrite whole elements via a regex (i.e. replace the entire element if it matches),
use %regex<-%
instead.
Usage
x %regex=% value
Arguments
x |
a character vector |
value |
c(pattern, replacement) |
Author(s)
Ben Wiseman, benjamin.wiseman@kornferry.com
Examples
# Apply a regular expression/substitution to x:
x <- c("a1b", "b1", "c", "d0")
# change any number to "x"
x %regex=% c("\\d+", "x")
print(x)
# "axb" "b" "c" "dx"
[Package roperators version 1.3.14 Index]