keep_in_bounds: Remove All Elements Out Of Bounds

View source: R/keep_in_bounds.R

keep_in_boundsR Documentation

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)

mlr-org/mlr3misc documentation built on April 13, 2024, 3:37 p.m.