Filter an object to only contained elements with desired .names.

keep_if_named(x, .names)

Arguments

x

A named R object.

.names

character, vector of names by which to filter x.

Value

Those elements of x whose name is in .names.

See also

Examples

library(salinasr) ages <- c(Tom = 20, Mary = 19, Sue = 43, Joe = 62) ages
#> Tom Mary Sue Joe #> 20 19 43 62
keep_if_named(ages, c("Mary", "Sue"))
#> Mary Sue #> 19 43