named_in | R Documentation |
Subset objects by name, preserving order
named_in(x, y)
not_named_in(x, y)
x |
An object with names. |
y |
A vector of names. |
named_in(x, y)
is similar to x[y]
except that:
unmatched elements of y
do not return an NA
element;
elements are returned in their original order within x
.
not_named_in(x, y)
returns elements of x
whose name is not
an element of y
.
For named_in
: x[names(x) %in% y]
.
For not_named_in
: x[! names(x) %in% y]
.
vec <- c(one = 1, two = 2, three = 3, four = 4)
vec |> named_in(c("two", "one", "three", "five"))
vec |> not_named_in(c("two", "three"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.