Questions tagged [xtable]

A function of an R package of the same name, used to convert an R object into an object that may be printed as a LaTeX or HTML table.

This function extracts tabular information from x and returns an object of class "xtable". The nature of the table generated depends on the class of x. For example, aov objects produce ANOVA tables while data.frame objects produce a table of the entire data.frame. One can optionally provide a caption (called a title in HTML) or label (called an anchor in HTML), as well as formatting specifications. Default values for align, digits, and display are class dependent.

The available method functions for xtable are given by methods(xtable). Users can extend the list of available classes by writing methods for the generic function xtable. These methods functions should have x as their first argument with additional arguments to specify caption, label, align, digits, and display. Optionally, other arguments may be present to specify how the object x should be manipulated. All method functions should return an object whose class if given by c("xtable","data.frame"). The resulting object can have attributes caption and label, but must have attributes align, digits, and display. It is strongly recommended that you set these attributes through the provided replacement functions as they perform validity checks.

The xtable package is a creation of David Dahl with contributions and suggestions from many others.

396 questions
78
votes
5 answers

General guide for creating publication quality tables using R, Sweave, and LaTeX

There are a range of tools available for creating publication quality tables using R, Sweave, and LaTeX. In particular, there are helper functions like latex in the Hmisc package, and xtable in the xtable package. I've also often written my own code…
Jeromy Anglim
  • 33,939
  • 30
  • 115
  • 173
58
votes
5 answers

add commas into number for output

I'm outputting a dataframe to html via xtable. I want to add commas to numbers in a couple columns of the table. I figured before I did my own paste hack I'd check if there is a built in way to do this.
Dan
  • 6,008
  • 7
  • 40
  • 41
49
votes
2 answers

Hiding NA's when printing a dataframe in knitr

I'm trying to print a table in knitr from a data frame using xtable . The table in the example below has the dimensions 3x7 but the third row only has one value, in the second column. The rest of the cells in the third row are 'NA'. When I compile…
Matt
  • 541
  • 1
  • 4
  • 8
43
votes
2 answers

How to remove the % lines in xtable table output by Knitr

By using xtable and knitr, I add a table to my RMD document and export to PDF file. ```{r, results='asis'} library(xtable) xtable(matrixtable) ```` It looks great except there is a line % latex table generated in R 3.1.0 by xtable 1.7-3 package %…
tky
  • 687
  • 1
  • 5
  • 9
38
votes
6 answers

possible to create latex multicolumns in xtable?

I am using xtable with R Markdown and knitr to produce .tex files that I call with \input{}. Works great, but I have not figured out how to create multicolumns like the one shown here. Does anyone know how to to this? So far I am using: tbl <-…
Eric Green
  • 7,385
  • 11
  • 56
  • 102
31
votes
1 answer

Control number of decimal places on xtable output in R

I am using Rmd file to create a report and I used xtable package to create the table. The output of the xtable shows the number of decimal places upto 2 digits. Is there a way to control the decimal places in xtable ? The sample code I used in Rmd…
Jd Baba
  • 5,948
  • 18
  • 62
  • 96
24
votes
1 answer

R, knitr, xtable, alternating row colors

I'm trying to produce a table with xtable in R using knitr with alternating row colors. I can print a table in the PDF output but can't quite figure out the add.to.row command in the xtable manual along with the colortbl package.
Jeremy Yeo
  • 493
  • 4
  • 9
24
votes
2 answers

Using xtable with R and Latex, math mode in column names?

I'm using xtable to compile tables from R automatically while compiling my TeX document. The question I have is how I get the variable names in the table (which in my case are the column names in a dataframe) to be in math mode. I have stored my…
hejseb
  • 2,064
  • 3
  • 18
  • 28
19
votes
3 answers

How to put a newline into a column header in an xtable in R

I have a dataframe that I am putting into a sweave document using xtable, however one of my column names is quite long, and I would like to break it over two lines to save space calqc_table<-structure(list(RUNID = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,…
PaulHurleyuk
  • 8,009
  • 15
  • 54
  • 78
18
votes
4 answers

Printing nice cross-tabulations in knitr

What I want is to print nice crosstabulations, either in a pdf file, or in a html file, from RStudio, using R, Markdown and knitr. I suspect I am missing something really obvious, because I cannot believe this is so hard. I make cross-tabs with…
astaines
  • 872
  • 2
  • 9
  • 20
17
votes
3 answers

R: xtable caption (or comment)

I want to put a comment under a table printed out by xtable. I figured that the best option would be to use the "caption" option: xtable(tablename, caption="This is a caption"). But this is somehow putting in a "Table 1" automatically, so that the…
user702432
  • 11,898
  • 21
  • 55
  • 70
17
votes
1 answer

xtable caption stays below

I created a table with the following Rsweave code. <>= require('xtable') res.table<-xtable(myfamDF, caption = 'Paired t-test of most common TF families', caption.placement="top", display =…
Sander Van der Zeeuw
  • 1,092
  • 1
  • 13
  • 35
17
votes
2 answers

Changing the Color of negative numbers to Red in a table generated with xtable()?

I'm writing a report in R with knitr. I'm using xtable() to generate tables in the report. One of my tables includes both negative and positive numbers. I'd like to change the color of negative numbers into red. How can I do that? Obviously, one…
Sam
  • 4,357
  • 6
  • 36
  • 60
16
votes
1 answer

Longtable in a knitr (PDF) document: using xtable (or kable)

I am new to knitr and I have had some very basic latex knowledge in the past, so I googled already hoping to find a solution that was already posted somewhere. However, I was not able to solve my problem. I am hoping someone will be kind enough to…
mdk
  • 181
  • 1
  • 1
  • 7
16
votes
4 answers

Preserve row/column labels from table() using kable and knitr

The table function in base R adds nice row/column labels, but when I use knitr::kable these go away. Any simple way to keep these, aside from adding them on the html/markdown side? Reproducible example: library(knitr) #…
arvi1000
  • 9,393
  • 2
  • 42
  • 52
1
2 3
26 27