Skip to contents

[Stable]

A simple wrapper of findInterval() function that invokes findInterval(), takes its output and replaces all the elements with \(0\) value to a custom number as specified in replacement argument.

Usage

h_find_interval(..., replacement = -Inf)

Arguments

...

Arguments passed on to base::findInterval

x

numeric.

vec

numeric, sorted (weakly) increasingly, of length N, say.

rightmost.closed

logical; if true, the rightmost interval, vec[N-1] .. vec[N] is treated as closed, see below.

all.inside

logical; if true, the returned indices are coerced into 1,...,N-1, i.e., 0 is mapped to 1 and N to N-1.

left.open

logical; if true all the intervals are open at left and closed at right; in the formulas below, \(\le\) should be swapped with \(<\) (and \(>\) with \(\ge\)), and rightmost.closed means ‘leftmost is closed’. This may be useful, e.g., in survival analysis computations.

replacement

(number)
a custom number to be used as a replacement for \(0\). Default to -Inf.

Examples

h_find_interval(1, c(2, 4, 6))
#> [1] -Inf
h_find_interval(3, c(2, 4, 6))
#> [1] 1
h_find_interval(1, c(2, 4, 6), replacement = -1)
#> [1] -1