From: Phil Spector <spector_at_stat.berkeley.edu>

Date: Mon, 21 Jun 2010 12:21:25 -0700 (PDT)

*> tt = table(df$a,df$b)
*

*> 100 * prop.table(tt) # total of all percentages = 100
*

*> 100 * prop.table(tt,1) # total of row percentages = 100
*

*> 100 * prop.table(tt,2) # total of column percentages = 100
*

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. Received on Mon 21 Jun 2010 - 19:23:59 GMT

Date: Mon, 21 Jun 2010 12:21:25 -0700 (PDT)

Erin -

Here's a reproducible example that should help answer your question:

*> set.seed(17)
**> df = data.frame(a=sample(letters[1:5],250,replace=TRUE),
*

+ b=sample(c('A','B'),250,replace=TRUE))

A B

a 11.2 9.2 b 12.0 6.8 c 7.2 10.4 d 10.8 13.2 e 8.4 10.8

A B

a 54.90196 45.09804 b 63.82979 36.17021 c 40.90909 59.09091 d 45.00000 55.00000 e 43.75000 56.25000

A B

a 22.58065 18.25397 b 24.19355 13.49206 c 14.51613 20.63492 d 21.77419 26.19048 e 16.93548 21.42857 - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spector_at_stat.berkeley.edu

On Mon, 21 Jun 2010, Erin Hodgess wrote:

> Dear R People:

*>
**> I have generated the following table:
**>
**>> table(zza$DEATH,zza$GENDER)
**>
**> F M
**> 2009-04-21 0 1
**> 2009-04-22 4 2
**> 2009-04-24 6 0
**> 2009-04-25 1 3
**> 2009-04-26 2 0
**> 2009-04-28 3 0
**> 2009-04-29 2 2
**>
**> However, instead of total counts in the F and M columns, I would like percents.
**>
**> How would I do this, please?
**>
**> thanks,
**> Erin
**>
**>
**>
**> --
**> Erin Hodgess
**> Associate Professor
**> Department of Computer and Mathematical Sciences
**> University of Houston - Downtown
**> mailto: erinm.hodgess_at_gmail.com
**>
**> ______________________________________________
**> 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.
**>
*

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. Received on Mon 21 Jun 2010 - 19:23:59 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Mon 21 Jun 2010 - 19:40:33 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*