[R] Cumulative Frequency table

jim holtman jholtman at gmail.com
Tue Sep 25 06:39:57 CEST 2007


?cumsum

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

 (0,39] (39,49] (49,59] (59,69] (69,79] (79,89]
     24      38      41      37      26      34
> cumsum(x)
 (0,39] (39,49] (49,59] (59,69] (69,79] (79,89]
     24      62     103     140     166     200
>


On 9/25/07, Chung-hong Chan <chainsawtiney at gmail.com> wrote:
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list