| findInterval3 | R Documentation |
The implementation of findInterval() in R from
Advanced R by Hadley Wickham. Given a vector of non-decreasing
breakpoints in v, find the interval containing each element of x; i.e.,
if i <- findInterval3(x,v), for each index j in x,
v[i[j]] <= x[j] < v[i[j] + 1], where v[0] := -Inf,
v[N+1] := +Inf, and N = length(v).
findInterval3(x, v, rightmost_closed = 0L, all_inside = 0L, left_open = 0L)
x |
The numeric vector of interest. |
v |
The vector of break points. |
rightmost_closed |
Logical; if true, the rightmost interval,
|
all_inside |
Logical; if true, the returned indices are coerced
into |
left_open |
Logical; if true, all intervals are open at left and closedat right. This may be useful, .e.g., in survival analysis. |
A vector of length(x) with values in 0:N where
N = length(v).
Kaifeng Lu, kaifenglu@gmail.com
x <- 2:18
v <- c(5, 10, 15) # create two bins [5,10) and [10,15)
cbind(x, findInterval3(x, v))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.