[R] Creating deciles on data using one variable

David Winsemius dwinsemius at comcast.net
Wed Nov 2 15:06:31 CET 2011


I need to deciles data containing more than one variables using any one
variable. I am using script below : 

id <-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) 
tot <-c(1230, 1230, 2345, 3456, 456, 4356, 123, 124, 987, 785, 5646, 345,
2345, 3456, 456, 4356, 123, 124, 987, 785)	
data <- data.frame ( cbind(id , tot)) 
data$decile<-cut(data$tot,quantile(data$tot,(0:10)/10),include.lowest=TRUE,lable=TRUE) 
data$decile 

New variable "decile" taking values as below where as I need it should take
values from 1,2..10, Where I am going wrong? 
-----------------

You have a factor with labels, but if you use as.numeric(data$decile) you
will get what you were aiming for.

-- 
david

--
View this message in context: http://r.789695.n4.nabble.com/Creating-deciles-on-data-using-one-variable-tp3973086p3973412.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list