overwrite_by_regex: Modify existing object by regular expression

Description Usage Arguments Author(s) Examples

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

1
x %regex=% value

Arguments

x

a character vector

value

c(pattern, replacement)

Author(s)

Ben Wiseman, benjamin.wiseman@kornferry.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 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"

roperators documentation built on Feb. 10, 2022, 1:07 a.m.