[R] How to find position in bin-data?

From: Antje Niederlein <niederlein-rstat_at_yahoo.de>
Date: Sat, 19 Mar 2011 13:18:26 +0100


Hi there,

probably there is a very simple solution, but I cannot think of one...

I have a vector with values:

data <- c(1,6,3,4,8,4,2,9)

and I have a vector with bin breaks:

bins <- c(1,3,5,7,9,11)

Now, I'd like to get for each data point the index of the bin-vector where the value falls in (or equals the lower bin break).

In the example case, I'd like to get:

c(1,3,2,2,4,1,5)

How would you solve it?

Antje



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 19 Mar 2011 - 12:20:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 19 Mar 2011 - 14:10:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive