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))
tt = table(df$a,df$b)
100 * prop.table(tt) # total of all percentages = 100
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
100 * prop.table(tt,1) # total of row percentages = 100
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
100 * prop.table(tt,2) # total of column percentages = 100
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
spec...@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.hodg...@gmail.com
______________________________________________
R-help@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@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.