[R] Binning Question

David Winsemius dwinsemius at comcast.net
Tue Apr 13 14:56:31 CEST 2010


On Apr 13, 2010, at 12:02 AM, Noah Silverman wrote:

> David,
>
> That helps me a lot.  Thanks!!!
>
> -N
>
>
>
> On 4/12/10 9:06 PM, David Winsemius wrote:
>> dat <- as.data.frame(matrix( rnorm(200), 100 , 2)) # bivariate  
>> normal n=100
>>
>> ab <- matrix( c(-5,-5,5,5), 2, 2) # interval [-5,5) x [-5,5)
>> nbin <- c( 20, 20) # 400 bins
>> bins <- bin2(dat, ab, nbin) # bin counts,ab,nskip
>>
>> dat$r1.cat <- cut(dat[,1],  breaks=seq(ab[1,1], ab[1,2],  
>> length.out=nbin[1]+1 ) )
>> dat$r2.cat <- cut(dat[,2], breaks=seq(ab[1,1], ab[1,2],  
>> length.out=nbin[1]+1))
>> dat$bicat <- with(dat, paste( as.numeric(r1.cat),  
>> as.numeric(r2.cat), sep="."))
>
> That's great, however something isn't coming out right.
>
> I pasted your code into R and it looks like I'm getting different  
> numbers bicat.

The numeric internals may not have bee the best choice if they got  
sorted improperly. Leave out the as.numeric.

> Should

You got cut off here. Hope all is well.

David.



More information about the R-help mailing list