Thanks for the reply. Another great option would be "missing" (like in SAS),
especially for factors.  I'm struggling to figure out how to do this with
"tables".

Daniel Cher, MD
[email protected]
+1-650-269-5763

This message and its attachments are confidential.

-----Original Message-----
From: Duncan Murdoch [mailto:[email protected]] 
Sent: Monday, January 13, 2014 2:13 AM
To: Daniel Cher; [email protected]
Subject: Re: [R] tables package and alternative to col percent

On 14-01-13 12:02 AM, Daniel Cher wrote:
> Library "tables" and tabular function is neato.
>
>
>
> I'm trying to figure out how to get percents other than just row and 
> columns. I'd like a percent of a factor.

That's a recent addition, still only on R-forge.
>
>
>
>
>
> library(tables)
>
>
>
> c=data.frame(
>
>        gender=c(1,1,1,1,2,2,2,2),
>
>        race=c(3,3,4,4,4,4,4,4)
>
> )
>
> tabular(
>
>        Factor(gender,"Gender") *
>
>        Factor(race, "Race") + 1 ~
>
>        (n=1) + Percent("col"),
>
>        data=c
>
> )
>
>
>
>
>
> The above produces:
>
>
>
> Gender Race n Percent
>
> 1      3    2  25
>
>          4    2  25
>
>   2      3    0   0
>
>          4    4  50
>
>          All  8 100
>
>>
>
>
>
>
>
> I'm looking for percents to have gender=1 or gender=2 as the denominator.
> I.e.,
>

You would get the table below using

Percent(denom = Equal(Gender))

Duncan Murdoch

>
>
>
>
>
>
> Gender Race n Percent
>
> 1      3    2  *50*
>
>          4    2  *50*
>
>   2      3    0   *0*
>
>          4    4  *100*
>
>          All  8 100
>
>>
>
>
>
>
>
>
>
>
>
> Daniel Cher, MD
>
>   <mailto:[email protected]> [email protected]
>
> +1-650-269-5763
>
>
>
> This message and its attachments are confidential.\ \  
> \...{{dropped:8}}
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to