Turning plain-text output into well-formatted tables can be a repetitive task, especially when many tests or models are being incorporated into a paper.
For R users, there are several methods that can make this task easier (though not much less repetitive), regardless of what typesetting system you use.
The xtable package produces LaTeX-formatted tables. Using xtable, specific kinds of R objects, such as linear model summaries, can be turned into "xtables", which can in turn be output to either LaTeX or HTML.
- Install the xtable package: install.packages("xtable")
- Load the xtable package: library(xtable)
- Create an xtable for the object that you want to export: newobject<-xtable(object)
- Export your xtabled object to LaTeX: print.xtable(newobject, type="latex", file="filename.tex")
- To export to HTML instead of LaTeX, use type="html" and use the .html extension in the filename
- To have R produce the proper markup in the console (instead of writing in to a file) omit the file=filename option
Other word processors
If, instead of LaTeX, you are using Word, OpenOffice, NeoOffice, etc., there is a way to produce more easily formatted tables. Just follow these steps:
- Create an xtable, as above, and print the output to an HTML file: print.xtable(newobject, type="html", file="filename.html")
- Open the generated HTML file in your browser (may I recommend Firefox)
- Copy the table contents and paste them into your word processor
- Convert the text to a table: In OpenOffice or NeoOffice: Select the text and go to Tools: Text <-> Table and select "Tabs" as the delimiter. In Word: Select the text and go to Table: Convert: Convert Text to Table, and use separate text at tabs
This technique is somewhat more convoluted than creating pure LaTeX output, but it is probably quicker than entering the output by hand.
Note: An alternative to xtable is the R2HTML package, which works similarly, but does not require xtable objects to be created in order to generate HTML output.