Skip to content

Proportions again

2 messages · Gabor Grothendieck, Marc Schwartz

#
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.


---
Date:   Sun, 29 Feb 2004 11:35:06 -0300 
From:   Carlos Mauricio Cardeal Mendes <mcardeal at atarde.com.br>
To:   <r-help at stat.math.ethz.ch> 
Subject:   [R] Proportions again 

 
Hello.

I asked before and it was great, cause as a beginner I learned a lot. But, if I have this in R (1 and 2 are codes for sex):
[1] 1 2 2 1 1 2 2 2

I´d like to obtain the proportion according to sex.So I type:
[1] 0.07692308 0.15384615 0.15384615 0.07692308 0.07692308 0.15384615 0.15384615
[8] 0.15384615

The result is OK, but I expected to see a simple frequency table or something like that:

1 0.375
2 0.625
1.0

How can I get this ? 

Thank you very much
#
On Sun, 2004-02-29 at 12:40, Gabor Grothendieck wrote:
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