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

keep_in_bounds

Remove All Elements Out Of Bounds


Description

Filters vector x to only keep elements which are in bounds [lower, upper]. This is equivalent to the following, but tries to avoid unnecessary allocations:

x[!is.na(x) & x >= lower & x <= upper]

Currently only works for integer x.

Usage

keep_in_bounds(x, lower, upper)

Arguments

x

(integer())
Vector to filter.

lower

(integer(1))
Lower bound.

upper

(integer(1))
Upper bound.

Value

(integer()) with only values in [lower, upper].

Examples

keep_in_bounds(sample(20), 5, 10)

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.