assign_by_regex: Assign to vector only where regular expression is matched

Description Usage Arguments Author(s) Examples

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

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
# 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"

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