fastFindInterval {spatstat.utils} | R Documentation |
Find Intervals Containing Given Data
Description
A faster alternative to findInterval
for intervals which are equally-spaced.
Usage
fastFindInterval(x, b, labels = FALSE, reltol = 0.001, dig.lab = 3L,
left.open=TRUE)
Arguments
x |
Data. Numeric vector of values that are to be classified. |
b |
Breakpoints. Numeric vector of increasing values that are the endpoints of the intervals. |
labels |
Logical value specifying whether to return a factor, whose levels are the string labels of the intervals. |
reltol |
Relative tolerance. A positive number. |
dig.lab |
Integer. Maximum number of digits to use in the labels
for the intervals, when |
left.open |
Logical value specifying whether intervals are left-open and
right-closed ( |
Details
This is an alternative to
findInterval(x, b, rightmost.closed=TRUE)
which seems to be faster when b
is equally spaced
and the length of x
is large.
If labels=FALSE
(the default), the result is an integer vector
giving, for each value x[i]
, the index j
of the interval that
contains x[i]
:
-
If
left.open=TRUE
(the default), the intervals are left-open and right-closed, except for the first interval. This means thatx[i]
belongs to thej
th interval ifb[j] < x[i] <= b[j+1]
forj > 1
andb[1] <= x[i] <= b[2]
forj=1
. -
If
left.open=FALSE
, the intervals are left-closed and right-open, except for the last interval. This means thatx[i]
belongs to thej
th interval ifb[j] <= x[i] < b[j+1]
forj < m
andb[m] <= x[i] <= b[m+1]
forj=m
wherem = length(b)-1
is the number of intervals.
If labels=TRUE
, the result is a factor, and the levels are
synthetic labels for the intervals, similar to those produced by
findInterval
.
Note that the default value of left.open
is TRUE
for fastFindInterval
but FALSE
for findInterval
.
Value
Integer vector, or factor.
Author(s)
Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner rolfturner@posteo.net and Ege Rubak rubak@math.aau.dk.
See Also
Examples
x <- runif(10)
b <- seq(0, 1, by=0.2)
fastFindInterval(x, b, labels=TRUE)