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? data$decile [1] (987,1.23e+03] (987,1.23e+03] (1.23e+03,2.34e+03] [4] (2.34e+03,3.46e+03] (301,456] (3.46e+03,4.36e+03] [7] [123,124] (124,301] (785,987] [10] (456,785] (4.36e+03,5.65e+03] (301,456] [13] (1.23e+03,2.34e+03] (2.34e+03,3.46e+03] (301,456] [16] (3.46e+03,4.36e+03] [123,124] (124,301] [19] (785,987] (456,785] -Ajit -- View this message in context: http://r.789695.n4.nabble.com/Creating-deciles-on-data-using-one-variable-tp3973086p3973086.html Sent from the R help mailing list archive at Nabble.com.
Creating deciles on data using one variable
2 messages · aajit75, David Winsemius
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.