keep_at: Keep or discard elements

Description Usage Arguments Value See Also Examples

View source: R/purrr-misc.R

Description

keep_at() keeps only the elements from specific positions while discard_at() does the opposite. The functions are wrappers around purrr::keep and purrr::discard, respectively.

Usage

1
2
3
keep_at(.x, .at)

discard_at(.x, .at)

Arguments

.x

A list or a vector.

.at

A character vector (names), a numeric vector (positions), a symbol or or a list generated by tidyselect select helpers.

Value

A list or a vector.

See Also

purrr::keep

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
x <- c("First" = 1, "Second" = 2, "Last" = 3)
keep_at(x, "Second")
keep_at(x, Second)
keep_at(x, 2)
keep_at(x, starts_with("Sec"))
#> Second 
#>      2

keep_at(x, ends_with("t"))
#> First  Last 
#>     1     3

x <- c(1, 2, 3)
discard_at(x, 1)
#> Second   Last 
#>      2      3

Nmisc documentation built on April 28, 2021, 5:10 p.m.