[R] Reading contingency tables

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jan 19 17:08:22 CET 2007


You are writing out x rather than ft. If you do:

write.ftable(ft, file = stdout())

it looks the same as the input.


On 1/19/07, Giovanni Petris <GPetris at uark.edu> wrote:
>
> 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/
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list