[R] ftable as latex (with Hmisc?)

Richard M. Heiberger rmh at temple.edu
Wed Nov 28 22:53:33 CET 2007


I think this does what you are asking for.  It should be
relatively easy to write a method

latex.ftable()

based on this.  One or two row.vars and one or two col.vars
should be straightforward (with n.rgroup and n.cgroup used
for the second row and column).

Rich

#### start here
df = data.frame(drug=sample(c("P","V"),100,TRUE),
                Hist1=sample(c("Pos","Neg"),100,TRUE),
                Hist2=sample(c("Pos","Neg"),100,TRUE))
ft.df <- ftable(drug~Hist1+Hist2,data=df)                
str(ft.df)

tmp <- unclass(ft.df)[,]
dimnames(tmp) <- list(rep(attr(ft.df, "row.vars")[[2]], 2),
                      attr(ft.df, "col.vars")[[1]])
ft.latex <- latex(tmp,
                  rgroup=attr(ft.df, "row.vars")[[1]],
                  n.rgroup=c(2,2),
                  cgroup=names(attr(ft.df, "col.vars"))[1])



More information about the R-help mailing list