[R] Reading contingency tables

Giovanni Petris GPetris at uark.edu
Fri Jan 19 16:52:57 CET 2007


Thank you, Prof Ripley. 

However, there is still something unclear to me about read.ftable.  I
noticed the following behavior, which I found strange. I expected
read.ftable to be an "inverse" of write.ftable, so to speak. Is there
something I am missing, or is this a problem in read.ftable?

Thanks,
Giovanni

> file <- tempfile()
> cat("             Intercourse\n",
+     "Race  Gender     Yes  No\n",
+     "White Male        43 134\n",
+     "      Female      26 149\n",
+     "Black Male        29  23\n",
+     "      Female      22  36\n",
+     file = file)
> file.show(file)
             Intercourse
 Race  Gender     Yes  No
 White Male        43 134
       Female      26 149
 Black Male        29  23
       Female      22  36

> ft <- read.ftable(file)
> ft ## OK so far
             Intercourse Yes  No
Race  Gender                    
White Male                43 134
      Female              26 149
Black Male                29  23
      Female              22  36
> x <- as.table(ft)
> write.ftable(ftable(x, col.vars=2:3), file)
> file.show(file)
        "Gender"      "Male"      "Female"     
        "Intercourse"  "Yes" "No"    "Yes" "No"
"Race"                                         
"White"                   43  134       26  149
"Black"                   29   23       22   36

> ft2 <- read.ftable(file)
> ft2
      Gender      Male             Female            
      Intercourse  Yes  No Yes  No    Yes  No Yes  No
Race                                                 
White               43 134  26 149     29  23  22  36
Black               43 134  26 149     29  23  22  36
> version
               _                           
platform       sparc-sun-solaris2.8        
arch           sparc                       
os             solaris2.8                  
system         sparc, solaris2.8           
status                                     
major          2                           
minor          4.1                         
year           2006                        
month          12                          
day            18                          
svn rev        40228                       
language       R                           
version.string R version 2.4.1 (2006-12-18)

-- 

Giovanni Petris  <GPetris at uark.edu>
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/



More information about the R-help mailing list