[R] tables package: How to remove column headings and alignment issues

Marius Hofert marius.hofert at math.ethz.ch
Fri Jan 18 21:08:15 CET 2013


Dear expeRts,

Here is a minimal example with the latest version of 'tables' (questions below):

require(tables)

saveopts <- table_options(toprule="\\toprule", midrule="\\midrule", bottomrule="\\bottomrule",
                          titlerule="\\cmidrule(lr)", rowlabeljustification="r")#, justification="r")

## data.frame
x <- expand.grid(beta=as.factor(c("95", "99", "99.9")),
                    m=as.factor(c(64, 256)),
                    p=as.factor(c(8, 64, 512)),
                    f=as.factor(c("A", "B")),
                    gamma=as.factor(c(0.25, 0.5)))
x <- cbind(x, value=1:nrow(x))

## tabular
(tab <- tabular(Heading("$p$") * Justify(c) * p *
                Heading("$m$") * Justify(c) * m *
                Heading("$\\gamma$") * Justify(c) * gamma
                ~
                Heading() * f * Heading() * beta *
                Heading() * value * Heading() * identity, data=x))
latex(tab)


Questions:

1) How can the column labels "f" and "beta" be removed? I tried to use Heading() to remove the labels, but some of them (actually all except "identity") still appear.

2) The above example leads to a tabular with columns aligned like this: rrrcccccc. However, if put in a .tex document, the table entries (1:9) are filled with \phantom{0}, so that the numbers do not appear centered (rather right-aligned). In contrast, the row labels (given in the first three columns) appear centered although they should be right-aligned.

3) Additionally using justification="r" in table_options() provides right-justification of the entries, however, they are now all wrapped in \multicolumn{1}{c}{...}. Why?

Cheers,

Marius



Here is a .tex wrapper for convenience:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[american]{babel}

\usepackage{tabularx}
\usepackage{booktabs}


\begin{document}
  % put code here
\end{document}



More information about the R-help mailing list