%regex<-% {roperators} | R Documentation |
Assign to vector only where regular expression is matched
Description
This takes two arguments just like gsub
- a patterns and a replacement.
It will totally overwrite any element where the pattern is matched with the second.
If you want to simply apply a regex (i.e. replace only the specific bit that matches),
use %regex=%
instead. If you want to replace with nothing (""), just just %-%
or
%-=% instead
.
Usage
x %regex<-% value
Arguments
x |
a character vector |
value |
c(pattern, replacement) |
Author(s)
Ben Wiseman, benjamin.wiseman@kornferry.com
Examples
# Overwrite elements that match regex:
x <- c("a1b", "b1", "c", "d0")
# overwrite any element containing a number
x %regex<-% c("\\d+", "x")
print(x)
# "x" "b" "c" "x"
[Package roperators version 1.3.14 Index]