Find indices i in vector xs such that either x=xs[i] or such that xs[i]<x<xs[i+1] or xs[i]>x>xs[i+1].

findintervals(x, xs)

Arguments

x

single number.

xs

numeric vector, not necessarily sorted.

Details

Contrary to findInterval, the vector xs in findintervals need not be sorted.

Value

Vector of indices in 1..length(xs). If none is found, returns integer(0).

Note

If x is equal to the last element in xs, the index length(xs) will also be returned.

Examples

xs <- zapsmall(sin(seq(0, 10*pi, len=100)))
findintervals(0, xs)
#>  [1]   1  10  20  30  40  50  60  70  80  90 100
#   1  10  20  30  40  50  60  70  80  90 100