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
7
votes
3 answers

Captions on tables in pdf documents generated by rmarkdown

How can I get captions on my table floats in pdf_document generated by rmarkdown? Using output: pdf_document: fig_caption: true and ```{r, fig.cap='a caption'} myplot ``` Generates a floating figure with myplot and the caption…
Rickard
  • 3,600
  • 2
  • 19
  • 22
7
votes
1 answer

Set column alignment and width for xtable generated longtable

Please consider the following MWE library(xtable) DF <- as.data.frame(UCBAdmissions) print(xtable(DF, align="p{0.4\textwidth}|p{0.15\textwidth} p{0.15\textwidth} p{0.15\textwidth}"), sanitize.text.function = function(x){x}, …
CptNemo
  • 6,455
  • 16
  • 58
  • 107
7
votes
2 answers

Adjust row height xtable R

There are couple of helpful posts round dealing with xtable but no one deals with this as far as my search abilities go. I would like to adjust row height in xtable (print). I'm printing a data.frame. print(xtable(...),...) Please note that I'm…
Maximilian
  • 4,177
  • 7
  • 46
  • 85
7
votes
1 answer

print.xtable with multi-line header?

I've been trying to create a table with a header that contains a like break. I am not too ambitious here and do not really care whether I just break extremely long strings or just have a two-line header in general. dat <- matrix(round(rnorm(9, 20,…
Matt Bannert
  • 27,631
  • 38
  • 141
  • 207
7
votes
1 answer

R --markdown to latex - tables do not show up

I am using Knitr in Rstudio, to generate markdown files. I display the tables via xtable package and it shows up nicely in html file. However, when I converd .md to latex via pandoc - the latex file does not contain the tables as it is supposed to…
Roark
  • 2,575
  • 2
  • 14
  • 8
6
votes
4 answers

In R, how to stop xtable from automatically rounding?

How do I disable automatic rounding in this case? > x <- c(2.222, 3.333, 6.6666) > df <- data.frame(x) > df x 1 2.2220 2 3.3330 3 6.6666 > xtable(df) Results in % latex table generated in R 2.11.1 by xtable 1.5-6 package % Tue Oct 25…
malana
  • 5,045
  • 3
  • 28
  • 41
6
votes
2 answers

How to convert Afex or car ANOVA models to lmer? Observed variables

In the afex package we can find this example of ANOVA analysis: data(obk.long, package = "afex") # estimate mixed ANOVA on the full design: # can be written in any of these ways: aov_car(value ~ treatment * gender + Error(id/(phase*hour)), data =…
skan
  • 7,423
  • 14
  • 59
  • 96
6
votes
1 answer

sorting a table for latex output with xtable

I´m trying to produce a sorted table and export in to latex. However it seems xtable cannot cope with sorted tables. Suggestions? a<-sample(letters,500,replace=T) b<-table(a) c<-sort(table(a),decreasing=T) xtable(b) xtable(c) //M
Misha
  • 3,114
  • 8
  • 39
  • 60
6
votes
2 answers

How to display numbers in scientific notation in ASCII tables?

I am trying to display extremely small numbers (<1E-12) in an ASCII table. (Believe me, I can't find any alternative.) So far I've tried stargazer and xtable. Neither of them seems to work. I can display the numbers in scientific notation with…
Jin
  • 103
  • 6
6
votes
1 answer

How to include a Percent Symbol in an xtable caption using Sweave in R

I'm trying to use Sweave to generate a statistical report, and am trying to put a caption on an xtable, however if I include the percent symbol this breaks things. Some example code <>= …
PaulHurleyuk
  • 8,009
  • 15
  • 54
  • 78
6
votes
1 answer

R: output a pivot-like table with subtotals

I'm trying to make a cross tabulation in R, and having its output resemble as much as possible what I'd get in an Excel pivot table. The objective is to replace a report made manually with Excel and Word with one automated with R Markdown; data…
s_a
  • 885
  • 3
  • 9
  • 22
6
votes
1 answer

How to include multiple tables programmatically into a Sweave document using R

I want to have a sweave document that will include a variable number of tables in. I thought the example below would work, but it doesn't. I want to loop over the list foo and print each element as it's own table. %…
PaulHurleyuk
  • 8,009
  • 15
  • 54
  • 78
6
votes
1 answer

How can I include hyperlinks in a table within an Sweave document?

I have a data frame containing hyperlinks that I would like to present as clickable links using Sweave. I know about xtable, but am not sure how to use it to treat the contents of a data frame as LaTeX commands.
David Lovell
  • 852
  • 6
  • 17
6
votes
1 answer

Use xtable to produce a Latex table with significance stars (***)

I am currently using xtable to generate Latex tables from R. It works fine, but in one of the tables I have significance stars to some of the numbers. Something like this dataframe X: 1 2 3 4 5 Test1 Test2 Test3 a "1.34" "0.43" "-0.26" "0.13"…
user3032689
  • 627
  • 1
  • 10
  • 23
6
votes
1 answer

With xtable and type = html how to add a class to a specific td tag

I'm trying to create a table in html with xtable, but I need to add a class to specific td tag, because I going to do an animation. The problems is that I can't do it without xtable because it is so slow. May be I need to represent this but with…
user2029940
  • 113
  • 2
  • 7