[R] Frequencies, proportions & cumulative proportions

Muenchen, Robert A (Bob) muenchen at utk.edu
Fri Oct 16 22:51:06 CEST 2009


Dear R-Helpers,

I've looked high and low for a function that provides frequencies,
proportions and cumulative proportions side-by-side. Below is the table
I need. Is there a function that already does it?

Thanks,
Bob

> # Generate some test scores
> myValues <- c(70:95)
> Score <- ( sample( myValues, size=1000, replace=TRUE) )
> head(Score)
[1] 77 71 81 88 83 93
> 
> # Get frequencies & proportions
> myTable <- data.frame( table(Score) )
> myTable$Prop <- prop.table( myTable$Freq )
> myTable$CumProp <-  cumsum( myTable$Prop )
> 
> # Print result
> myTable
   Score Freq  Prop CumProp
1     70   44 0.044   0.044
2     71   42 0.042   0.086
3     72   40 0.040   0.126
4     73   40 0.040   0.166
5     74   43 0.043   0.209
6     75   45 0.045   0.254
7     76   46 0.046   0.300
8     77   40 0.040   0.340
9     78   46 0.046   0.386
10    79   43 0.043   0.429
11    80   37 0.037   0.466
12    81   29 0.029   0.495
13    82   33 0.033   0.528
14    83   39 0.039   0.567
15    84   31 0.031   0.598
16    85   32 0.032   0.630
17    86   31 0.031   0.661
18    87   37 0.037   0.698
19    88   30 0.030   0.728
20    89   33 0.033   0.761
21    90   43 0.043   0.804
22    91   41 0.041   0.845
23    92   37 0.037   0.882
24    93   39 0.039   0.921
25    94   42 0.042   0.963
26    95   37 0.037   1.000
>

=========================================================
Bob Muenchen (pronounced Min'-chen),
Manager, Research Computing Support
U of TN Office of Information Technology 
Stokely Management Center, Suite 200
916 Volunteer Blvd., Knoxville, TN 37996-0520
Voice: (865) 974-5230
FAX: (865) 974-8655
Please help us improve: http://oit.utk.edu/feedback   
Web: http://oit.utk.edu/research
Map to Office: http://www.utk.edu/maps    
Newsletter: http://oit.utk.edu/research/news.php
=========================================================




More information about the R-help mailing list