Try findInterval :).

Let me try to explain what I mean with this title. I have a vector of numbers. The numbers represent bin limits. For example c(1,2,3) is a vector that represents 2 bins. The first is [1,2) and the second is [2,3]. I need a function that returns the bin index given any number within the vector range (in our example the range is 1 to 3). So the function must return 1 if it receives a 1.4. It returns 2 if it receives 2.7 etc…

The function you are looking for is findInterval.

### Like this:

Like Loading...

*Related*

## About joelgranados

I'm fascinated with how technology and science impact our reality and am drawn to leverage them in order to increase the potential of human activity.