[R] Cross-tabulations next to each other

Charilaos Skiadas skiadas at hanover.edu
Thu Feb 22 16:01:33 CET 2007


I have the following relatively simple problem. Say we have three  
factors, and we want to create a cross-tabulation against each of the  
other two:

x <- factor(rbinom(5, 1, 1/2))
y <- factor(rbinom(5, 1, 1/2))
z <- factor(rbinom(5, 1, 1/2))
table(x,y)
table(x,z)

This looks like:

    y
x   0 1
   0 2 0
   1 1 2

    z
x   0 1
   0 1 1
   1 2 1

I would like to get (surely this will look a mess in non-monospaced  
fonts):

    y    z
x   0 1  0 1
   0 2 0  1 1
   1 1 2  2 1

Or something along those lines. Then I would like to convert this to  
a LaTeX table, in the obvious sort of way.

I couldn't find an answer with a quick look through the  
documentation. Are these two things already done, before I try to  
roll my own?

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College



More information about the R-help mailing list