Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

drop_element

Filter Elements in a Vetor


Description

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

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

Usage

drop_element(x, pattern, regex = TRUE, ...)

drop_element_regex(x, pattern, ...)

drop_element_fixed(x, ...)

keep_element(x, pattern, regex = TRUE, ...)

keep_element_fixed(x, ...)

keep_element_regex(x, pattern, ...)

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

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)

textclean

Text Cleaning Tools

v0.9.3
GPL-2
Authors
Tyler Rinker [aut, cre], ctwheels StackOverflow [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.