[R] crosstabs

Mark Lamias mlamias at isr.umich.edu
Wed May 17 15:25:56 CEST 2000


>>Hi all!
>>What is the equivalent R function of SPLUS crosstabs? 
>>Thank you.
>>
>>Danar.
>>Stat. Inst. Umea Univ.
>>Umea, Sweden


"qftable" will produce contingency tables in R.  Code from the help file is
pasted below.



>  ## Start with a contingency table.
>      data(Titanic)
>      ftable(Titanic, row.vars = 1:3)
                   Survived  No Yes
Class Sex    Age                   
1st   Male   Child            0   5
             Adult          118  57
      Female Child            0   1
             Adult            4 140
2nd   Male   Child            0  11
             Adult          154  14
      Female Child            0  13
             Adult           13  80
3rd   Male   Child           35  13
             Adult          387  75
      Female Child           17  14
             Adult           89  76
Crew  Male   Child            0   0
             Adult          670 192
      Female Child            0   0
             Adult            3  20
>      ftable(Titanic, row.vars = 1:2, col.vars = "Survived")
             Survived  No Yes
Class Sex                    
1st   Male            118  62
      Female            4 141
2nd   Male            154  25
      Female           13  93
3rd   Male            422  88
      Female          106  90
Crew  Male            670 192
      Female            3  20
>      ftable(Titanic, row.vars = 2:1, col.vars = "Survived")
             Survived  No Yes
Sex    Class                 
Male   1st            118  62
       2nd            154  25
       3rd            422  88
       Crew           670 192
Female 1st              4 141
       2nd             13  93
       3rd            106  90
       Crew             3  20
> 
>      ## Start with a data frame.
>      data(mtcars)
>      x <- ftable(mtcars[c("cyl", "vs", "am", "gear")])
>      x
          gear  3 4 5
cyl vs am            
4   0  0        0 0 0
       1        0 0 1
    1  0        1 2 0
       1        0 6 1
6   0  0        0 0 0
       1        0 2 1
    1  0        2 2 0
       1        0 0 0
8   0  0       12 0 0
       1        0 0 2
    1  0        0 0 0
       1        0 0 0
>      ftable(x, row.vars = c(2, 4))
        cyl 4   6    8  
        am  0 1 0 1  0 1
vs gear                 
0  3        0 0 0 0 12 0
   4        0 0 0 2  0 0
   5        0 1 0 1  0 2
1  3        1 0 2 0  0 0
   4        2 6 2 0  0 0
   5        0 1 0 0  0 0

Mark J. Lamias
Department of Statistics
Department of Political Science
Survey Methodology Program/Survey Research Center
Institute for Social Research - University of Michigan
426 Thompson Street, Room 315
Ann Arbor, Michigan 48104-2321
(734) 647-5381



-----Original Message-----
From: dandon at capa.stat.umu.se [mailto:dandon at capa.stat.umu.se]
Sent: Wednesday, May 17, 2000 4:33 AM
To: R mailing list
Subject: [R] crosstabs



Hi all!
What is the equivalent R function of SPLUS crosstabs? 
Thank you.

Danar.
Stat. Inst. Umea Univ.
Umea, Sweden

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

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