keep_at {Nmisc}R Documentation

Keep or discard elements

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

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

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


[Package Nmisc version 0.3.7 Index]