%regex<-% | R Documentation |
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
.
x %regex<-% value
x |
a character vector |
value |
c(pattern, replacement) |
Ben Wiseman, benjamin.wiseman@kornferry.com
# 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"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.