[R] Best way to coerce numerical data to a predetermined histogram bin?

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Thu Dec 6 23:21:47 CET 2012

Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
Sent from my phone. Please excuse my brevity.

Jonathan Greenberg <jgrn at illinois.edu> wrote:

>Say I have a set of histogram breaks:
># With bin ids:
># and some data (note that some of it falls outside the breaks:
>What is the MOST EFFICIENT way to "classify" data into the histogram
>(return the bin_ids) and, say, return NA if the value falls outside of
>By classify, I mean if the data value is greater than one break, and
>than or equal to the next break, it gets assigned that bin's ID (note
>length(breaks) = length(bin_ids)+1)
>Also note that, as per this example, the bins are not necessarily equal
>I can, of course, cycle through each element of data, and then move
>breaks, stopping when it finds the correct bin, but I feel like there
>probably a faster (and more elegant) approach to this.  Thoughts?

More information about the R-help mailing list