[R] Cumulative Frequency table

Chung-hong Chan chainsawtiney at gmail.com
Tue Sep 25 06:15:01 CEST 2007


Dear R gurus,

I think this question is very trivial, but I search around the HELP
file and this maillist can come up with no answer. Suppose I have a
vector called AGE like this

> sort(AGE)
  [1] 30 34 35 37 37 38 38 38 38 39 39 40 40 42 42 43 43 43 43 43 43 44
 [23] 44 44 44 44 44 44 45 45 45 46 46 46 46 46 46 47 47 47 47 47 47 48
.....

I can count the frequency based on some cut point using table with cut,

> table(cut(AGE, b=c(0,39,49,59,69,79,89)))

 (0,39] (39,49] (49,59] (59,69] (69,79] (79,89]
     11      46      70      45      16       1

How can I calculate the cumulative Frequency, e.g.

0-39 11
40-49 57
50-59 127
60-69 172
70-79 188
80-89 189

using R command?



-- 
CH Chan
Research Assistant - KWH
http://www.macgrass.com



More information about the R-help mailing list