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.
h_find_interval(..., replacement = -Inf)Arguments passed on to base::findInterval
xnumeric.
vecnumeric, sorted (weakly) increasingly, of length N,
say.
rightmost.closedlogical; if true, the rightmost interval,
vec[N-1] .. vec[N] is treated as closed, see below.
all.insidelogical; if true, the returned indices are coerced
into 1,...,N-1, i.e., 0 is mapped to 1
and N to N-1.
left.openlogical; 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.
checkSortedlogical indicating if vec should be checked,
i.e., is.unsorted(vec) is asserted to be false. Setting
this to FALSE skips the check gaining speed, but may return
nonsense results in case vec is not sorted.
checkNAlogical indicating if each x[i] should be checked
as with is.na(.). Setting this to FALSE in case
of NA's in x[] may result in platform dependent nonsense.
(number)
a custom number to be used as a replacement
for \(0\). Default to -Inf.
h_find_interval(1, c(2, 4, 6))
h_find_interval(3, c(2, 4, 6))
h_find_interval(1, c(2, 4, 6), replacement = -1)
Run the code above in your browser using DataLab