[R] Reordering the results from table(cut()) by break argument

Mark Heckmann mark.heckmann at gmx.de
Wed Dec 2 18:18:26 CET 2009


I have a vector and need to count how many data points fall inside  
each bin:

dat <- rnorm(100)
breaks <- -3:3
table((cut(dat, breaks)))

(-3,-2] (-2,-1]  (-1,0]   (0,1]   (1,2]   (2,3]
       3      13      42      30      12       0

if I reverse the breaks vector, the results remains the same:
breaks <- rev(breaks)
table((cut(dat, breaks)))

(-3,-2] (-2,-1]  (-1,0]   (0,1]   (1,2]   (2,3]
       3      13      42      30      12       0

What I would like is break to also determine the order of the table  
output, in this case it should also be reversed, like:
( 3, 2] ( 2, 1]  ( 1,0]   (0,-1]   (-1,-2]   (-2,-3]
       0      12      30      42      13       3

Thus I would like to reorder the vector using break, but I do not know  
how.

TIA
Mark
–––––––––––––––––––––––––––––––––––––––
Mark Heckmann
Dipl. Wirt.-Ing. cand. Psych.
Vorstraße 93 B01
28359 Bremen
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com




More information about the R-help mailing list