Re: [R] Some problems with latex(ftable)

From: Richard M. Heiberger <>
Date: Sun 16 Jul 2006 - 07:03:57 EST

The ftable structure is not an ordinary matrix. Instead, it has the body of the table with several cbind- and rbind-ed rows and columns of label information. The example in ?ftable has two row factors and two column factors.

Continuing with the example in ?ftable, enter

tmp <- ftable(mtcars$cyl, mtcars$vs, mtcars$am, mtcars$gear, row.vars = c(2, 4),

              dnn = c("Cylinders", "V/S", "Transmission", "Gears"))


To get what you are looking for, you will need to intercept write.ftable with, for example,

trace(write.ftable, exit=recover)

then do

tmp.latex <- latex(t(x))

Now open up t.latex and prepend

and append

then latex it.

This gets you close to what you want and you can work with the generated t.tex file to get the rest of the detail. Or you can work with the numerous arguments we built into latex (see ?latex) to get some of them automatically generated.

tmp2.latex <- latex(t(x), col.just=rep(c("l","r"), c(3,6)),

                    n.rgroup=c(3,6), file="t2.tex")

Now open up t2.latex and pre- and append the latex controls to it.

This works well for one or two examples. To do many, then you will need to follow Frank's suggestion and build all of this into a method. Once the method works well, send it to Frank and he will consider including it in the next release (Frank, I hope that's a fair offer I make for you to do).

This raises a question from me to the R developers. I would have written write.ftable to return t(x), not ox. print is constrained to return its argument. I thought write had more freedom. Then I would respecify

print.ftable <- function (x, digits = getOption("digits"), ...) {

     write.ftable(x, quote = FALSE, digits = digits)


Had this been done then the current task would simplify to


Te question is: why was write.ftable designed to follow the print.ftable constraint on returned value.

ps. I just designed the method. Take write.ftable, drop the last line and give it a new name. then you can latex the output of that new function.

Rich mailing list PLEASE do read the posting guide! Received on Sun Jul 16 07:19:14 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 16 Jul 2006 - 16:14:03 EST.

Mailing list information is available at Please read the posting guide before posting to the list.