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
11
votes
1 answer

Create a table in R with header expanding on two columns using xtable or any package

I want to combine the tables from two dataframes and want to export that table to latex. The table that i want to create looks as follows. Note, the table below is created using excel. From xtable in R I was able to export the table for two…
Jd Baba
  • 5,948
  • 18
  • 62
  • 96
11
votes
3 answers

Include dimension names in row and column headers for LaTeX-formatted contingency table

If the categories of the attributes in a contingency table are mere numbers, using only these numbers as column/row header is not enough -- a description what the numbers mean is called for. The picture below shows the cross-classification of…
krlmlr
  • 25,056
  • 14
  • 120
  • 217
10
votes
5 answers

Creating a latex table from ftable object in R

Let me create some data before I ask my question. my.data <- data.frame(A = sample(seq(1,100,by=5),10,replace=TRUE),W = rnorm(10),X =sample(1:10),Y = sample(c("yes", "no"), 10, replace =…
Stat-R
  • 5,040
  • 8
  • 42
  • 68
10
votes
6 answers

Combining several regression tables into one for use in xtable with Sweave in R

xtable in Sweave works awesome, but does one table per regression. You can feed it a data frame, too, so I have been manually rbinding and pasteing results into data frames, but that doesn't seem very scalable. Is there a more automated/robust…
Richard Herron
  • 9,760
  • 12
  • 69
  • 116
10
votes
1 answer

set digits row wise with print.xtable in R?

I got some report that has a few tables which contain proportion AND absolute values. Now I'd like to display rows that contain proportion at a digits=2 accuracy while absolute values are just shown with digits=0. I know this is possible…
Matt Bannert
  • 27,631
  • 38
  • 141
  • 207
9
votes
1 answer

Changing the font size of table using print.xtable

I want to change the font size of the table using print.xtable. Using print(xT, size="\\tiny") works but I don't know other options for size. Something like size="7pt" would be nice.
b4154
  • 353
  • 3
  • 4
  • 14
9
votes
1 answer

knitr, R Markdown, and xtable: xtable tables within HTML table

Suppose I want to print HTML tables using xtable, side-by-side. I tried doing this in an .Rmd file with:
`r functionThatPrintsAnHTMLTableUsingxtable` `r…
Brash Equilibrium
  • 1,357
  • 4
  • 14
  • 35
9
votes
2 answers

How to get dimnames in xtable.table output?

I'd like to have the dimensions labeled in my xtable output. However, the table method of xtable does not output dimension labels even when I specify them manually to table: set.seed(10) d <- data.frame(x=sample(1:4),y=sample(1:4)) tb <- with(d,…
Ari B. Friedman
  • 71,271
  • 35
  • 175
  • 235
8
votes
1 answer

Column names on each page with xtable in Sweave

I want to have column names on each page of the xtable. \documentclass{article} \usepackage{graphicx} \usepackage{longtable} \begin{document} <<>>= x <- matrix(rnorm(1000), ncol = 10) x.big <- xtable(x,label='tabbig',caption='Example of…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
8
votes
1 answer

How to change column heading using xtable in R?

I have the following piece of code: tableData <- head(original_table[,c("column1", "column2", "column3")]) library(xtable) xt <- xtable(tableData) print(xt,type="html") The…
radiobrain77
  • 613
  • 1
  • 6
  • 19
8
votes
1 answer

knitr doesn't convert xtable output on R 3.0.2

I would like to create a tex table using xtable(). Here's my minimal example which worked when I used the same R version on Win…
Gerome Bochmann
  • 496
  • 6
  • 19
8
votes
1 answer

Can't get sanitize text function to work in xtable when not in math mode

EDIT I found the answer and posted below. The only reason I had thought it was working in math mode was because I was running an example and never saw the sanitize-text-function argument was being passed to the print method. I'll accept this answer…
AdamO
  • 4,283
  • 1
  • 27
  • 39
7
votes
2 answers

Adding a horizontal line between the rows in a latex table using R xtable

I have a sample latex table generation code like this df<-data.frame(name=rep(letters[1:7],each=24),salary=runif(24*7,100,200)) lst<-tapply(df$salary,df$name,matrix,nrow=4,byrow=T) xlst<-lapply(lst,xtable) Now I want to introduce \hdashline…
alex
  • 81
  • 1
  • 4
7
votes
1 answer

Split headings in groups over multiple rows in xtable

How can I produce a table through xtable with headings in groups, like the following?
Hugh
  • 15,521
  • 12
  • 57
  • 100
7
votes
1 answer

xtable adding a title on top and a caption under the table

I want to put a caption title on the xtable in a Rnw document. Here's the code. Unfortunately, I'm not able to add a caption under the table. I've tried the \caption{} function, but it won't print the PDF. I've seen R: xtable caption (or comment),…
M. Beausoleil
  • 3,141
  • 6
  • 29
  • 61
1 2
3
26 27