[R] Cut breaks in descending order

Wing Keong Lew wingkeong at outlook.com
Fri Apr 3 14:09:41 CEST 2015


Hi,

Is it a requirement to provide the break intervals of the cut function in ascending order? The help documentation for cut didn't specify this but the labels returned are reversed if I indicate the break intervals in a descending order. Here is an example

tbl<-data.frame(x=c(0:10))
tbl$ascending<-cut(tbl$x, breaks=c(0,3,5,9,99), labels=c('<3','4-5','6-9','>9'), include.lowest=T)
tbl$descending<-cut(tbl$x, breaks=c(99,9,5,3,0), labels=c('>9','6-8','4-5','<3'), include.lowest=T)
tbl
    x ascending descending
1   0        <3        >9
2   1        <3        >9
3   2        <3        >9
4   3        <3        >9
5   4       4-5       6-8
6   5       4-5       6-8
7   6       6-9       4-5
8   7       6-9       4-5
9   8       6-9       4-5
10  9       6-9       4-5
11 10        >9        <3

Appreciate any guidance on this.
Regards
Wing Keong

 		 	   		  


More information about the R-help mailing list