drop_element: Filter Elements in a Vetor

Description Usage Arguments Value Examples

View source: R/drop_element.R

Description

drop_element - Filter to drop the matching elements of a vector.

keep_element - Filter to keep the matching elements of a vector.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

Arguments

x

A character vector.

pattern

A regex pattern to match for exclusion.

regex

logical. If setting this to TRUE please use drop_element_regex or keep_element_regex directly as this will provide better control and optimization.

...

Other arguments passed to grep if regex. If fixed, then elements to drop/keep.

Value

Returns a vector with matching elements removed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
x <- c('dog', 'cat', 'bat', 'dingo', 'dragon', 'dino')
drop_element(x, '^d.+?g')
keep_element(x, '^d.+?g')
drop_element(x, 'at$')
drop_element(x, '^d')
drop_element(x, '\\b(dog|cat)\\b')

drop_element_fixed(x, 'bat', 'cat')
drops <- c('bat', 'cat')
drop_element_fixed(x, drops)

Example output

[1] "cat"  "bat"  "dino"
[1] "dog"    "dingo"  "dragon"
[1] "dog"    "dingo"  "dragon" "dino"  
[1] "cat" "bat"
[1] "bat"    "dingo"  "dragon" "dino"  
[1] "dog"    "dingo"  "dragon" "dino"  
[1] "dog"    "dingo"  "dragon" "dino"  

textclean documentation built on May 2, 2019, 7:22 a.m.