https://github.com/cran/pracma
Tip revision: 708a2ad382a163d1eef5af0665e3ae2aad200ced authored by HwB on 21 March 2013, 00:00:00 UTC
version 1.4.5
version 1.4.5
Tip revision: 708a2ad
findintervals.R
##
## f i n d i n t e r v a l s . R Find Interval Indices
##
findintervals <- function(x, xs) {
if (length(x) == 0 || length(xs) == 0) return(c())
if (!is.vector(x, mode="numeric") || !is.vector(x, mode="numeric"))
stop("Arguments 'x' and 'xs' must be numeric vectors.")
if (length(x) != 1)
stop("Length of vector 'x' must be 1.")
n <- length(xs)
xsx <- xs - x
i0 <- which(xsx == 0)
i1 <- which(xsx[1:(n-1)] * xsx[2:n] < 0)
return(sort(c(i0, i1)))
}