# Export/format output from pairwise.t.test to LaTeX

I am trying to format the output from pairwise.t.test into LaTeX, but have not found a way of doing this. Has anyone got any suggestions?

EDIT: As this is a one-time only report where I do need to customize the variable names, and row-/column headings, I was hoping to avoid using Sweave.

-
Thanks for the tags Rob, I was unable to create the latex tag myself. –  Tormod Aug 16 '10 at 8:42

Does this help?

> library(xtable)
> attach(airquality)
> res <- pairwise.t.test(Ozone, Month)
> xtable(res$p.value, caption=res$method)
% latex table generated in R 2.9.2 by xtable 1.5-6 package
% Mon Aug 16 04:24:21 2010
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrrrr}
\hline
& 5 & 6 & 7 & 8 \\
\hline
6 & 1.00 &  &  &  \\
7 & 0.00 & 0.05 &  &  \\
8 & 0.00 & 0.05 & 1.00 &  \\
9 & 1.00 & 1.00 & 0.00 & 0.00 \\
\hline
\end{tabular}
\caption{t tests with pooled SD}
\end{center}
\end{table}

-
This works perfectly, an easy method of achieving exactly what I wanted. –  Tormod Aug 16 '10 at 8:48

One way that you can do the above task without using Sweave is as follows:

1. Write a custom export function from R that takes the pairwise.t.test object and outputs latex code.
2. Use \input{...} in your LaTeX document to input this file into your LaTeX document.

With regards to step 1, there are many functions that are useful. Here are a few:

• paste() is useful for concatenating elements including latex elements with R objects
• formatC() is useful for formatting numbers
• write() is useful for exporting the combined LaTeX/R character vector from R to a text file

There are also a variety of LaTeX table generating functions (e.g., see the xtable package)

-
Thank you for the tips on writing a custom export and the useful functions. –  Tormod Aug 16 '10 at 8:47