[R] breaks

Martin Maechler
Fri, 13 Jun 2003 06:32:30 -0000

Erin, even though you've already summarized,
I think the optimal answer to your question is

  findInterval()

{there's also R-C API you can use from your  C/C++}

Martin


>>>>> "Erin" == Erin Hodgess <hodgess at
uhddx01.dt.uh.edu>
>>>>>     on Thu, 12 Jun 2003 13:33:52 -0500 (CDT) writes:

    Erin> Dear R People: I have a question about a "sorting"
    Erin> problem, please.

    Erin> I have a vector xx:

    >> xx

    Erin>  [1] -2.0 1.4 -1.2 -2.2 0.4 1.5 -2.2 0.2 -0.4 -0.9

    Erin> and a vector of breaks:

    >> xx.y

    Erin> [1] -2.2000000 -0.9666667 0.2666667 1.5000000

    Erin> I want to produce another vector z which contains the
    Erin> number of the class that each data point is in.

    Erin> for instance, xx[1] is between xx.y[1] and xx.y[2], so
    Erin> z[1] == 1

    Erin> this can be accomplished via loops, but I was
    Erin> wondering if there is a more efficient method, please.

    Erin> By the way, eventually, there will be many more data
    Erin> points and more classes.

    Erin> thank you for any help!

    Erin> sincerely, Erin Hodgess mailto: hodgesse at uhd.edu

    Erin> Version 1.7.0 R for Windows

    Erin> ______________________________________________
    Erin> R-help at stat.math.ethz.ch mailing list
    Erin> https://www.stat.math.ethz.ch/mailman/listinfo/r-help