Skip to content
Prev 270315 / 398502 Next

Classifying values by interval

On 08/31/2011 06:00 PM, Ted Harding wrote:
Hi Ted,
Are you looking for something like this?

x<-sample(1:10,20,TRUE)
x
  [1]  5 10 10  9  1  1  1  7  2  1  2  1  1  1  9  7  8  5  6  8
binx<-cut(x,breaks=0:10)
as.numeric(binx)
  [1]  5 10 10  9  1  1  1  7  2  1  2  1  1  1  9  7  8  5  6  8

As binx is a factor, coercing it to numeric should return the bin number 
for each value.

Jim