[R] xtable and table()
Andrew Perrin
aperrin at email.unc.edu
Wed Nov 14 19:55:35 CET 2001
Greetings-
A relatively small request, but here goes.
I have some crosstabs, generated with table(), in R:
> table(pg.df$grouptype,pg.df$age)
0 1 2 3 4
B 1 3 6 8 3
C 1 3 4 10 7
P 0 2 9 9 8
S 2 9 4 5 16
U 0 15 15 3 0
X 0 0 0 0 0
I would like to export these in latex format using xtable(). But it
appears there's no appropriate method for xtable():
xtable(data.frame(table(pg.df$grouptype,pg.df$age)))
gives a flattened three-way matrix:
1 & B & 0 & 1.00 \\
2 & C & 0 & 1.00 \\
3 & P & 0 & 0.00 \\
4 & S & 0 & 2.00 \\
(etc.)
xtable(data.frame(table(pg.df$grouptype,pg.df$age)))
gives a similar result. I'd like:
& 0 & 1 & 2 & 3 & 4 \\
B & 1 & 3 & 6 & 8 & 3 \\
(etc.)
Thanks.
----------------------------------------------------------------------
Andrew J Perrin - andrew_perrin at unc.edu - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
269 Hamilton Hall, CB#3210, Chapel Hill, NC 27599-3210 USA
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list