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

Using booktabs with Rmarkdown

Booktabs and xtable fail with Rmarkdown using RStudio. The Tufte template works fine, but using a standard .Rmd file fails with the error message: ! Undefined control sequence. l.133 \toprule pandoc.exe: Error producing PDF from TeX source Error:…
r.bot
  • 5,309
  • 1
  • 34
  • 45
4
votes
1 answer

Problems cross referencing in LaTex with knitr and xtable

I am currently working with R Studio to produce PDF documents with R/knitr in LaTex. Within these documents I want to present part of my results in tables that I want to refer to in the text. I produce these tables using the xtable package within R…
Sarina
  • 548
  • 3
  • 10
4
votes
2 answers

Shiny Dashboard inconsistent box and table formatting

I've made a simple shiny dashboard with dummy tables below. When I run it and the window is too thin, the columns of the tables run over the edge of the boxes. If I make the window wide enough, the tables then fit in the boxes. Can anyone help with…
Eugene Brown
  • 4,032
  • 6
  • 33
  • 47
4
votes
1 answer

How do I print superscripts in a table using xtable and sweave?

So my problem statement is as follows : I have defined a data frame in my Sweave document (.Rnw extension) using the following code: <>= table2_1_rows <- c('Students with compulsory Evaluations', 'Teachers…
4
votes
1 answer

Whitespace around an xtable

I'm trying to insert a small table in a body of text using knitr. The I'm not sure if it's a knitr/sweave problem or with xtable but I get a ton of whitespace around the table. Here is an example of the output with the table set to 5cm: When I…
GregRousell
  • 997
  • 2
  • 13
  • 23
4
votes
2 answers

Formatting html table in R

I would like to improve the look of an html table that I generate in R using the package xtable: library(xtable) html.table = xtable() digits(html.table) = 2 I print the table using: html.tab = print(html.table, type = "html",…
Mayou
  • 8,498
  • 16
  • 59
  • 98
4
votes
1 answer

Adding extra column name and row name to a table in R?

I have a table which I generated from table() function and I further use xtable to print it as follows: FF NF NN Sum FF 8 0 0 8 NF 7 8 0 15 NN 3 1 4 8 I want to add an additional column name and a rowname…
Arihant
  • 589
  • 9
  • 24
4
votes
3 answers

knitr xtable highlight and add horizontal lines for the same row,

I am using knitr and xtable to automate my reporting procedure. I want to highlight a few rows of a table and have a horizontal line right above each row highlighted. The .Rnw file I am using reads as below: \usepackage{colortbl,…
user2854008
  • 1,161
  • 4
  • 17
  • 23
4
votes
0 answers

Adding horizontal lines to tables created by xtable in R Markdown

I'm trying to create simple tables with R Markdown (.Rmd), using RStudio. The most customizable and easily applicable way I found is xtable package. Even though xtable should produce a table with horizontal lines by default. What I should get would…
HBat
  • 4,873
  • 4
  • 39
  • 56
4
votes
1 answer

Standalone latex table from amended xtable function

I'm trying to create an automated R function which creates a latex file that can be run (without any further amendments to the Latex code) by an external Latex program. I'm aware of KnitR and Sweave but I need something much simpler. Basically for…
Mercelo
  • 231
  • 1
  • 5
  • 14
4
votes
1 answer

xtable left just

the default of xtable is \begin{center}. I would like to make it: \begin{left} and \end{left} as well. Code: library(xtable) xtable(anova(lm(mpg~hp, data=mtcars))) Desired outcome: \begin{table}[ht] \begin{left} \begin{tabular}{lrrrrr} \hline &…
Tyler Rinker
  • 108,132
  • 65
  • 322
  • 519
4
votes
1 answer

Customizing xtables by adding horizontal lines and merging cells?

I've seen similar questions on SO-most of them have not been answered. Those that were answered usually suggest not using xtable since it's not flexible to customization. I've attached two pictures: 1) my generated table from xtable 2) my ideal…
Sam
  • 4,357
  • 6
  • 36
  • 60
3
votes
1 answer

Multi-panel regression tables in R

I am trying to create a regression table that has two panels with overlapping but not identical dependent variables. For each panel, I want a title indicating the name of each panel as well as the dependent variables for each regression. # rm(list =…
Thomas J. Brailey
  • 151
  • 1
  • 2
  • 12
3
votes
2 answers

Replace accents in string vector with Latex code

Define: df <- data.frame(name=c("México","Michoacán"),dat=c(1,2)) s.t. > df name dat 1 México 1 2 Michoacán 2 When I print this table to a .tex file using xtable the accented characters get garbled, which is no surprise. I would…
Fred
  • 1,833
  • 3
  • 24
  • 29
3
votes
2 answers

How to get addNA and xtable to work together?

I'm using xtabs to tabulate some data that contains NAs. In order to make sure the totals are complete, I'm using addNA to count the ones with missing factor levels. However, this causes problems when using xtable to export to LaTeX for Sweaving…
James
  • 65,548
  • 14
  • 155
  • 193