Revision 03698027c2d84118bd0c53c4a9a5b5d23676f388 authored by HwB on 01 October 2012, 00:00:00 UTC, committed by Gabor Csardi on 01 October 2012, 00:00:00 UTC
1 parent 9fdea5d
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)))
}
Computing file changes ...