[R] Proportions again

Gabor Grothendieck ggrothendieck at myway.com
Mon Mar 1 01:27:12 CET 2004


That's true; however, 

CrossTable(x,x)

does give the desired counts and proportions in the margin
line at the bottom.  See the row labelled Column Total in
the following example based on Carlos' vector:

> sex<-c(1,2,2,1,1,2,2,2)
> CrossTable(sex,sex)

 
   Cell Contents
|-----------------|
|               N |
|   N / Row Total |
|   N / Col Total |
| N / Table Total |
|-----------------|

 
Total Observations in Table:  8 

 
             | sex 
         sex |         1 |         2 | Row Total | 
-------------|-----------|-----------|-----------|
           1 |         3 |         0 |         3 | 
             |     1.000 |     0.000 |     0.375 | 
             |     1.000 |     0.000 |           | 
             |     0.375 |     0.000 |           | 
-------------|-----------|-----------|-----------|
           2 |         0 |         5 |         5 | 
             |     0.000 |     1.000 |     0.625 | 
             |     0.000 |     1.000 |           | 
             |     0.000 |     0.625 |           | 
-------------|-----------|-----------|-----------|
Column Total |         3 |         5 |         8 | 
             |     0.375 |     0.625 |           | 
-------------|-----------|-----------|-----------|


---
Date:   Sun, 29 Feb 2004 13:48:27 -0600 
From:   Marc Schwartz <MSchwartz at MedAnalytics.com>
To:   <ggrothendieck at myway.com> 
Cc:   <mcardeal at atarde.com.br>,R-Help <r-help at stat.math.ethz.ch> 
Subject:   RE: [R] Proportions again 

 
On Sun, 2004-02-29 at 12:40, Gabor Grothendieck wrote:
> Several people have alrady answered you by this time and
> in addition to their answers you might also be interested
> in CrossTable in package gregmisc.

Gabor,

Thanks for pointing out CrossTable().

Just as a quick heads up/clarification for Carlos, CrossTable() is
designed to cross-tabulate two vectors and generate counts,
row/column/table proportions and other results from the 2 dimensional
cross-tab in a (hopefully) nicely formatted fashion.

It is not presently designed to handle generating proportions from the
tabulation of a single vector with repeating values (such as Carlos'
example) and will generate an error message if a single vector is
passed.

In that scenario, as many folks have already recommended, the
combination of table() and prop.table() would be preferred.

HTH,

Marc Schwartz




More information about the R-help mailing list