| Line 28... |
Line 28... |
| 28 |
i.e., \code{\link{is.unsorted}(vec)} is asserted to be false. Setting
|
28 |
i.e., \code{\link{is.unsorted}(vec)} is asserted to be false. Setting
|
| 29 |
this to \code{FALSE} skips the check gaining speed, but may return
|
29 |
this to \code{FALSE} skips the check gaining speed, but may return
|
| 30 |
nonsense results in case \code{vec} is not sorted.}
|
30 |
nonsense results in case \code{vec} is not sorted.}
|
| 31 |
\item{checkNA}{logical indicating if each \code{x[i]} should be checked
|
31 |
\item{checkNA}{logical indicating if each \code{x[i]} should be checked
|
| 32 |
as with \code{\link{is.na}(.)}. Setting this to \code{FALSE} in case
|
32 |
as with \code{\link{is.na}(.)}. Setting this to \code{FALSE} in case
|
| 33 |
of \code{NA}'s in \code{x[]} may result in platform dependent nonsense.}
|
33 |
of \code{NA}s in \code{x[]} may result in platform-dependent nonsense.}
|
| 34 |
}
|
34 |
}
|
| 35 |
\description{
|
35 |
\description{
|
| 36 |
Given a vector of non-decreasing breakpoints in \code{vec}, find the
|
36 |
Given a vector of non-decreasing breakpoints in \code{vec}, find the
|
| 37 |
interval containing each element of \code{x}; i.e., if
|
37 |
interval containing each element of \code{x}; i.e., if
|
| 38 |
\code{i <- findInterval(x,v)}, for each index \code{j} in \code{x}
|
38 |
\code{i <- findInterval(x,v)}, for each index \code{j} in \code{x}
|
| Line 93... |
Line 93... |
| 93 |
N <- 100
|
93 |
N <- 100
|
| 94 |
X <- sort(round(stats::rt(N, df = 2), 2))
|
94 |
X <- sort(round(stats::rt(N, df = 2), 2))
|
| 95 |
tt <- c(-100, seq(-2, 2, length.out = 201), +100)
|
95 |
tt <- c(-100, seq(-2, 2, length.out = 201), +100)
|
| 96 |
it <- findInterval(tt, X)
|
96 |
it <- findInterval(tt, X)
|
| 97 |
tt[it < 1 | it >= N] # only first and last are outside range(X)
|
97 |
tt[it < 1 | it >= N] # only first and last are outside range(X)
|
| - |
|
98 |
stopifnot(identical(it,
|
| 98 |
stopifnot(identical(it, ## suppressing the checks is faster *BUT* dangerous, unless
|
99 |
## Suppressing the checks is faster *BUT* dangerous, unless
|
| 99 |
## you *know* that X is sorted and tt contains no NA's
|
100 |
## you *know* (like here) that the breakpoints are sorted
|
| - |
|
101 |
## and the input contains no missing values, respectively.
|
| 100 |
findInterval(tt, X, checkSorted=FALSE, checkNA=FALSE)))
|
102 |
findInterval(tt, X, checkSorted=FALSE, checkNA=FALSE)
|
| - |
|
103 |
))
|
| 101 |
|
104 |
|
| 102 |
## 'left.open = TRUE' means "mirroring" :
|
105 |
## 'left.open = TRUE' means "mirroring" :
|
| 103 |
N <- length(v)
|
106 |
N <- length(v)
|
| 104 |
stopifnot(identical(
|
107 |
stopifnot(identical(
|
| 105 |
findInterval( x, v, left.open=TRUE) ,
|
108 |
findInterval( x, v, left.open=TRUE) ,
|