[R] Cross-tabulations next to each other

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Thu Feb 22 16:27:54 CET 2007


maybe cbind() is close to what you're looking for, e.g.,

tb1 <- table(x, y)
tb2 <- table(x, z)

cbind(tb1, tb2)


Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Charilaos Skiadas" <skiadas at hanover.edu>
To: "R-Mailingliste" <r-help at stat.math.ethz.ch>
Sent: Thursday, February 22, 2007 4:01 PM
Subject: [R] Cross-tabulations next to each other


>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
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list