The implementation of findInterval() in R from
Advanced R by Hadley Wickham. Given a vector of non-decreasing
breakpoints in v, find the interval containing each element of x; i.e.,
if i <- findInterval3(x,v), for each index j in x,
v[i[j]] <= x[j] < v[i[j] + 1], where v[0] := -Inf,
v[N+1] := +Inf, and N = length(v).
A vector of length(x) with values in 0:N where
N = length(v).
Arguments
x
The numeric vector of interest.
v
The vector of break points.
rightmost_closed
Logical; if true, the rightmost interval,
vec[N-1] .. vec[N] is treated as closed if left_open is false,
and the leftmost interval, vec[1] .. vec[2] is treated as
closed if left_open is true.
all_inside
Logical; if true, the returned indices are coerced
into 1, ..., N-1, i.e., 0 is mapped to 1 and
N is mapped to N-1.
left_open
Logical; if true, all intervals are open at left and
closedat right. This may be useful, .e.g., in survival analysis.