Skip to content
Prev 157371 / 398506 Next

quantile / centile

Donald Braman wrote:
You can use

cnt <- cut(x, quantile(x, seq(0,1,0.01)), include=TRUE)
names(cnt) <- 1:100 # if you want to get rid of ugly interval labels

With Harrells Hmisc packages, there's also

cnt <- cut2(x, g=100)

Or you can take a more basic approach and do

N <-sum(!is.na(x))
cnt <- ceiling(rank(x)/N*100)