[R] Re: xtable and table()

Peter Baker peter.baker at cmis.csiro.au
Thu Nov 15 05:15:41 CET 2001


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list