[R] newbie query: simple crosstabs

Bernardo Rangel Tura tura at centroin.com.br
Wed Apr 8 11:25:38 CEST 2009


On Tue, 2009-04-07 at 16:33 -0400, Donald Braman wrote:
> I've been playing around with various table tools, trying to construct a
> fairly simple cross-tab.  It shouldn't be hard, but for some reason it
> turning out to be (for me).
> 
> If I want to see how many men and how many women agree with a agree/disagree
> question (coded 1,0), I can do this:
> 
> >attach(mydata)
> >mytable <- table(male, q1.bin) # gender and a binary response variable
> >prop.table(mytable, 1) # row percentages
>      q1.bin
> male      0      1
>    0 0.3988 0.6012
>    1 0.2879 0.7121
> 
> I can repeat that for each of the items I want gender breakdowns for (q2,
> q3, q4 ....).   But what I really want is a table that shows the percentage
> answering yes (coded as 1) across many, many binary response items.  E.g.,
> 
> 
> male q1.bin q2.bin q3.bin ...
>    0 0.6012 0.3421 0.9871 ...
>    1 0.7121 0.6223 0.0198 ...
> 
> I've tried various combinations of apply & cbind, but to no avail. It would
> be easy in SPSS crosstabs, but darnit, I want to use R!

Donald,

The other solutions is using command CrossTable of package gmodels.
-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil




More information about the R-help mailing list