Returns an integer vector to order vector x
according to vector y
.
Arguments
- x
(
vector())
.- y
(
vector()
).- na_last
(
logical(1)
)
What to do with values inx
which are not iny
?NA
: Extra values are removed.FALSE
: Extra values are moved to the beginning of the new vector.TRUE
: Extra values are moved to the end of the new vector.
Value
(integer()
).
Examples
# x subset of y
x = c("b", "a", "c", "d")
y = letters
x[reorder_vector(x, y)]
#> [1] "a" "b" "c" "d"
# y subset of x
y = letters[1:3]
x[reorder_vector(x, y)]
#> [1] "a" "b" "c"
x[reorder_vector(x, y, na_last = TRUE)]
#> [1] "a" "b" "c" "d"
x[reorder_vector(x, y, na_last = FALSE)]
#> [1] "d" "a" "b" "c"