Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

reorder_vector

Reorder Vector According to Second Vector


Description

Returns an integer vector to order vector x according to vector y.

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

(integer()).

Examples

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

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

mlr3misc

Helper Functions for 'mlr3'

v0.10.0
LGPL-3
Authors
Michel Lang [cre, aut] (<https://orcid.org/0000-0001-9754-0393>), Patrick Schratz [aut] (<https://orcid.org/0000-0003-0748-6624>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.