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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Andrew
I believe that in order to get the correct format, xtable() needs its
argument as a matrix rather than a table
For example, try something like
library(xtable)
data(state)
x <- matrix(table(state.division, state.region),
nrow=nlevels(state.division),ncol=nlevels(state.region))
rownames(x) <- levels(state.division)
colnames(x) <- levels(state.region)
xtable(x)
Regards
Peter Baker
=========================================================Andrew Perrin (aperrin
at email.unc.edu) wrote
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
--
Dr Peter Baker, Statistician (Bioinformatics/Genetics),
CSIRO Mathematical & Information Sciences, 233 Middle St/
PO Box 120, CLEVELAND, QLD 4163 Australia.
Email: Peter.Baker at csiro.au
Phone:+61 7 3826 7263 Fax:+61 7 3826 7304
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._