[R] locating intervals

Martin Maechler
Wed, 09 Aug 2006 09:25:09 -0000

I'm pretty sure you want to use

findInterval()

Why did you not find it?
In other words,  what did you try to find it?

Regards,
Martin Maechler, ETH Zurich

>>>>> "halldor" == halldor bjornsson
<halldor.bjornsson at gmail.com>
>>>>>     on Tue, 8 Aug 2006 16:47:18 +0000 writes:

    halldor> Hi , I have two sorted vectors X and Xi, where the
    halldor> range of Xi lies within the range of X.

    halldor> For an element in Xi, I want to find the
    halldor> neigbouring data in X, e.g. find an index ix so
    halldor> that for element number k, then X[ix[k]] < X[k] <
    halldor> X[ix[k] +1] # also OK with "<=" on either one, but
    halldor> not both

    halldor> This is easy to code by looping over the data in
    halldor> X,Xi, but I suspect there may be a faster and more
    halldor> elegant way to do this in R.

    halldor> In Python (Numeric) the same can be achieved with
    halldor> ix=Numeric.searchsorted(X[1:-1],Xi), which is quite
    halldor> compact.

    halldor> So, does anyone know of a corresponding R call that
    halldor> can achive the same?

    halldor> Sincerely, Halld?r

    halldor> -- Halldor Bjornsson Weatherservice R & D Icelandic
    halldor> Met. Office