On Sun, 30 Nov 2008, Andrew Choens wrote:
I have a dataframe with the following variables:
idnum areagender raceetc.
I would like to make a table that looks like
areagender race
M FB W A
1 4 53 5 1
2 6 74 6 3
etc.
Basically, I want to make a single broad table with a number of sub-set
tables. I have tried:
Well you are asked to provide commented, minimal, self-contained,
reproducible code, and I see nothing here I can reproduce.
But here is a start:
tab1 - xtabs(~agegp+tobgp,esoph)
tab2 - xtabs(~agegp+alcgp,esoph)
cat(paste(capture.output(tab1),capture.output(tab2),'\n'))
tobgpalcgp
agegp 0-9g/day 10-19 20-29 30+ agegp 0-39g/day 40-79 80-119 120+
25-344 4 3 4 25-34 4 4 34
35-444 4 4 3 35-44 4 4 43
45-544 4 4 4 45-54 4 4 44
55-644 4 4 4 55-64 4 4 44
65-744 4 4 3 65-74 4 3 44
75+ 4 4 1 2 75+ 3 4 22
It is left as an exercise to figure out how to redo the first line to move
'alcgp' over ' 0-3' and how to delete the redundant 'agegp; column. See
?nchar
?substring
and maybe
?sprintf
for some pointers.
HTH,
Chuck
cbind(table(area, gender), table(area, race))
But, when I do this, I lose the labels gender / race. This makes it a
lot harder to understand my factor labels. when I use cbind, I get this:
M F B W A
1 4 5 3 5 1
2 6 7 4 6 3
Although, it is technically correct, I really want to keep my factor
labels. I also tried this with xtabs and get the same results. Any
ideas? I saw a relatively recent thread asking a similar question, but
the proposed solution did not work for me, so I thought I would ask the
questions again.
If I am missing someting terribly obvious, I apologize.
thanks.
--
Insert something humorous here. :-)
__
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.
Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED] UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
__
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.