[R] locating intervals
Martin Maechler
maechler at stat.math.ethz.ch
Wed Aug 9 11:25:09 CEST 2006
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
More information about the R-help
mailing list