[R] tables package and alternative to col percent

Duncan Murdoch murdoch.duncan at gmail.com
Mon Jan 13 11:12:33 CET 2014


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