reorder_vector {mlr3misc}R Documentation

Reorder Vector According to Second Vector

Description

Reorders x to have the same order as y. Duplicated elements will be removed.

Usage

reorder_vector(x, y, na_last = NA)

Arguments

x

(vector()).

y

(vector()).

na_last

(logical(1))
What to do with values in x which are not in y?

  • 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

(vector()) x with reordered values.

Examples

# x subset of y
x = c("b", "a", "c", "d")
y = letters
reorder_vector(x, y)

# y subset of x
y = letters[1:3]
reorder_vector(x, y)
reorder_vector(x, y, na_last = TRUE)
reorder_vector(x, y, na_last = FALSE)

[Package mlr3misc version 0.8.0 Index]