Folks:

Say I have a set of histogram breaks:

breaks=c(1:10,15)

# With bin ids:

bin_ids=1:(length(breaks)-1)

# and some data (note that some of it falls outside the breaks:

data=runif(min=1,max=20,n=100)

***

What is the MOST EFFICIENT way to "classify" data into the histogram bins
(return the bin_ids) and, say, return NA if the value falls outside of the
bins.

By classify, I mean if the data value is greater than one break, and less
than or equal to the next break, it gets assigned that bin's ID (note that
length(breaks) = length(bin_ids)+1)

Also note that, as per this example, the bins are not necessarily equal
widths.

I can, of course, cycle through each element of data, and then move through
breaks, stopping when it finds the correct bin, but I feel like there is
probably a faster (and more elegant) approach to this.  Thoughts?

--j





-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 217-300-1924
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to