[R] Proportions again

Gabor Grothendieck
2004-03-01T01:26:43Z

I agree its overkill but prop.table generalizes to mulitple
dimensions, in which case it becomes comparable to CrossTable,
so I thought it was worth mentioning.

By the way, as the author of CrossTable, perhaps you
might might consider generalizing CrossTable to the 1D
case too?

---
Date:   Sun, 29 Feb 2004 19:19:29 -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 18:27, Gabor Grothendieck wrote:
> 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)

snip

OK....true. I had not considered that approach from a design
perspective, but it does provide the requisite information.

One could feasibly reduce some of the complexity of the table by setting
some of the prop.* arguments to false:

CrossTable(sex, sex, prop.c = FALSE, prop.t = FALSE)

which would yield:


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


Total Observations in Table: 8


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


This gives you the proportions in the row margins versus the columns.
You still end up with some extraneous data, but perhaps a little less
so.

Just seems like overkill to get the same information that:

> prop.table(table(sex))
sex
1 2
0.375 0.625

gives you, without the lengthy function call. :-)


Thanks Gabor.

Best regards,

Marc