R: Filter Elements in a Vetor

drop_element {textclean} | R Documentation

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

[Package textclean version 0.9.3 Index]