Here is my problem:
How can I find the index of the histogram bin in which a number falls?
In Matlab, the solution is easy. HISTC does the job:
[counts,bin] = histc(data,edges)
“bin” being what I am looking for.
But I am working in R, and the hist function of R doesn’t propose the functionnality. I think I could manage with some lines of code (using some things as min and <), but as I need to do it for many numbers, I would like to find a more elegant solution.
Since I am not very experienced in R, I hope there could exist a tricky solution, taking to the problem in another way.
The
histfunction will return the breakpoints between the bins if you do not already have them. You can then use thefindIntervalfunction to find which interval/bin each of your points falls into: