Diberikan vektor titik henti sementara yang tidak menurun dalam vec, carilah interval yang memuat setiap elemen x; yaitu, jika i
findInterval(x, vec, rightmost.closed = FALSE, all.inside = FALSE,
left.open = FALSE)
| Parameter | Deskripsi |
|---|---|
x |
numeric. |
vec |
numeric, sorted (weakly) increasingly, of length N, say. |
rightmost.closed |
logical; if true, the rightmost interval, vec[N-1] .. vec[N] is treated as closed, see below. |
all.inside |
logical; if true, the returned indices are coerced into 1,…,N-1, i.e., 0 is mapped to 1 and N to N-1. |
left.open |
logical; 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. |
# NOT RUN {
x <- 2:18
v <- c(5, 10, 15) # create two bins [5,10) and [10,15)
cbind(x, findInterval(x, v))
N <- 100
X <- sort(round(stats::rt(N, df = 2), 2))
tt <- c(-100, seq(-2, 2, len = 201), +100)
it <- findInterval(tt, X)
tt[it < 1 | it >= N] # only first and last are outside range(X)
## 'left.open = TRUE' means "mirroring" :
N <- length(v)
stopifnot(identical(
findInterval( x, v, left.open=TRUE) ,
N - findInterval(-x, -v[N:1])))
# }