[R] Binning Question

Noah Silverman noah at smartmediacorp.com
Tue Apr 13 04:07:45 CEST 2010


I'm trying to setup some complicated binning with statistics and could
use a little help.

I've found the bin2 function from the ash package, but it doesn't do
everything I need.  My intention is to copy some of their code and then
modify as needed.

I have a vector of two columns:

              r1          r2
[1,]  0.03516559  0.03102128
[2,]  0.02162539  0.14847034
[3,]  0.02210339  0.06539623
[4,] -0.07547792 -0.08859678
[5,]  0.03655620  0.05412436
[6,]  0.06513828  0.06053050

I'd like to create a 2 dimension list of bins with the frequency counts
for each bin.  The bin2 function does this.  Then it gets interesting.

I'd like to add a column to my vector that has the "bin label" for the
bin that row would belong to.  (I can see how to do this with lots of
nasty loops and greater-than, less-than calculations, but that gets
messy.)  There must be an easier way.

So, If I made 10 bins for each column (r1,r2), I'd have 100 bins. 
(bin1, bin2, bin3, etc.)  I want to label each ROW in my data set with
the bin it would belong to.  (I intend to do more work with them after
this, but this starts.  Each row gets transformed depending on the bin
it belongs to, etc..)



More information about the R-help mailing list