Given a vector of non-decreasing breakpoints in
vec, find the interval containing each element of
x; i.e., if
i <- findInterval(x,v), for each index
x v[i[j]] ≤ x[j] < v[i[j] + 1] where v := - Inf, v[N+1] := + Inf, and
N <- length(v). At the two boundaries, the returned index may differ by 1, depending on the optional arguments
findInterval(x, vec, rightmost.closed = FALSE, all.inside = FALSE)
- numeric, sorted (weakly) increasingly, of length
- logical; if true, the rightmost interval,
vec[N-1] .. vec[N]is treated as closed, see below.
- logical; if true, the returned indices are coerced into
findInterval finds the index of one vector
x in another,
vec, where the latter must be non-decreasing. Where this is trivial, equivalent to
apply( outer(x, vec, ">="), 1, sum), as a matter of fact, the internal algorithm uses interval search ensuring O(n * log(N)) complexity where
n <- length(x) (and
N <- length(vec)). For (almost) sorted
x, it will be even faster, basically O(n).
rightmost.closed = TRUE, the result for
x[j] = vec[N] ( = max(vec)), is
N - 1 as for all other values in the last interval.
vector of length
length(x) with values in
N <- length(vec), or values coerced to
1:(N-1) if and only if
all.inside = TRUE (equivalently coercing all x values inside the intervals). Note that
NAs are propagated from
Inf values are allowed in both
approx(*, method = "constant") which is a generalization of
ecdf for computing the empirical distribution function which is (up to a factor of n) also basically the same as
Documentation reproduced from R 3.0.2. License: GPL-2.