[R] tables package and alternative to col percent
Daniel Cher
djcher at gmail.com
Fri Jan 17 06:36:35 CET 2014
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
djcher at gmail.com
+1-650-269-5763
This message and its attachments are confidential.
-----Original Message-----
From: Duncan Murdoch [mailto:murdoch.duncan at gmail.com]
Sent: Monday, January 13, 2014 2:13 AM
To: Daniel Cher; r-help at r-project.org
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:djcher at gmail.com> djcher at gmail.com
>
> +1-650-269-5763
>
>
>
> This message and its attachments are confidential.\ \
> \...{{dropped:8}}
>
> ______________________________________________
> R-help at r-project.org 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.
>
More information about the R-help
mailing list