## Agresti (1990), page 157, Table 5.8.
## Not in ftable standard format, but o.k.
file <- tempfile()
cat("Intercourse
",
"Race Gender Yes No
",
"White Male 43 134
",
"Female 26 149
",
"Black Male 29 23
",
"Female 22 36
",
file = file)
file.show(file)
ft1 <- read.ftable(file)
ft1
unlink(file)
## Agresti (1990), page 297, Table 8.16.
## Almost o.k., but misses the name of the row variable.
file <- tempfile()
cat(""Tonsil Size"
",
""Not Enl." "Enl." "Greatly Enl."
",
"Noncarriers 497 560 269
",
"Carriers 19 29 24
",
file = file)
file.show(file)
ft <- read.ftable(file, skip = 2,
row.var.names = "Status",
col.vars = list("Tonsil Size" =
c("Not Enl.", "Enl.", "Greatly Enl.")))
ft
unlink(file)
ft22 <- ftable(Titanic, row.vars = 2:1, col.vars = 4:3)
write.ftable(ft22, quote = FALSE)
write.ftable(ft22, quote = FALSE, method="row.compact")
write.ftable(ft22, quote = FALSE, method="col.compact")
write.ftable(ft22, quote = FALSE, method="compact")
op <- options(warn = 2) # no warnings allowed
stopifnot(dim(format(ft)) == 4:5,
dim(format(ftable(UCBAdmissions))) == c(6,9))
meths <- c("non.compact", "row.compact", "col.compact", "compact")
dimform <-
function(ft) sapply(meths, function(M) dim(format(ft, method = M)))
m.eq <- function(M,m) all.equal(unname(M), m, tolerance = 0)
## All format(..) w/o warnings:
stopifnot(m.eq(print(dimform(ft22)),
rbind(11:10, rep(7:6, each = 2))),
m.eq(print(dimform(ftable(Titanic, row.vars = integer()))),
rbind(rep(6:5,2), 33)))
options(op)
Run the code above in your browser using DataLab