Binning a numeric variable in R
Posted
by McPeterson
on Stack Overflow
See other posts from Stack Overflow
or by McPeterson
Published on 2010-03-24T01:41:13Z
Indexed on
2010/03/24
1:43 UTC
Read the original article
Hit count: 336
I have a vector X that contains positive numbers that I want to bin/discretize. For this vector, I want the numbers [0, 10) to show up just as they exist in the vector, but numbers [10,∞) to be 10+.
I'm using:
x <- c(0,1,3,4,2,4,2,5,43,432,34,2,34,2,342,3,4,2)
binned.x <- as.factor(ifelse(x > 10,"10+",x))
but this feels klugey to me. Does anyone know a better solution or a different approach?
- mcpeterson
© Stack Overflow or respective owner