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
15
votes
2 answers

How to include NA data in a table

I've recently been using the package tab in R to build frequency tables. Using the tabfreq() or the tabmulti() functions, the default output excludes NA values. Does anyone know the command to include NA values within these functions?
gfa2001
  • 227
  • 1
  • 2
  • 10
15
votes
7 answers

Counts & Percentages in xTable, Sweave, R, cross tabulations

Edit: Building off of aL3xa's answer below, I've modified his syntax below. Not perfect, but getting closer. I still haven't found a way to make xtable accept \multicolumn{} arguments for columns or rows. It also appears that Hmisc handles some of…
Chase
  • 67,710
  • 18
  • 144
  • 161
14
votes
1 answer

Getting Column-Names to Wrap in R/Kable() HTML Table

I'm trying to produce an HTML table output from an R data frame and am unable to get some long column names to wrap for a multi-line header row. Here is a minimal reproducible example of my current code and output:…
Max Power
  • 8,265
  • 13
  • 50
  • 91
14
votes
3 answers

Sweave xtable: how to position tables between text?

I have a number of tables with text around them describing them. Something like this: This table shows blah blah... <>= print( xtable(x, caption = "blah", label = "tab:four", table.placement = "tbp",…
griffin
  • 3,158
  • 8
  • 37
  • 34
14
votes
2 answers

How to suppress automatic table name and number in an .Rmd file using xtable or knitr::kable?

I'd like to name my tables from R scripts without the automatic Table 1:... prefix when using xtable() or knitr::kable() in an .Rmd file. Output is a pdf document. Here's a reproducible example from an .Rmd file: --- title: "Suppress automatic table…
vestland
  • 55,229
  • 37
  • 187
  • 305
14
votes
4 answers

R - Conditional row highlighting in HTML table created using xtable or kable

I'm pretty much a beginner at programmatically formatting R output, but I've got a basic understanding of knitr, xtable, Markdown, and Pandoc's ability to convert one markup format to another. What I want to do is write an R dataframe df to an HTML…
mcjudd
  • 1,520
  • 2
  • 18
  • 33
13
votes
1 answer

How to center LaTeX xtable output in full text width

I am using tufte-handout (http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf) to create a small report in latex. I have a file code.Rnw that I knit into code.tex. Below is my…
user1830307
13
votes
1 answer

Customize xtable

I'd like to customize xtable for export into LaTeX. I know there are some questions abot xtable here, but I couldn't find the specific things I'm looking for. Here is an example of how my table might look like: my.table <-…
AnjaM
  • 2,941
  • 8
  • 39
  • 62
12
votes
2 answers

Repeat headers when using xtable with longtable option

Is there a way to repeat the top row / set headers when generating an xtable with a longtable option ? For eg., if I have tableSb <- xtable(df, caption="A Very Long Table", label="ALongTable") print(tableSb, include.rownames=TRUE,…
xbsd
  • 2,438
  • 4
  • 25
  • 35
12
votes
4 answers

Variables Overview with xtable in R

I'm wondering if it's possible to create a xtable from the command str(x) to get an overview from the variables you use. This would be a nice feature to introduce someone to the dataset, but it's annoying to create it by yourself. So whta I tried is…
user734124
  • 489
  • 8
  • 20
12
votes
1 answer

Use xtable to print html table in R markdown file

I would like to print a nicer table with a data frame in R mark down file, and I know how to use kable to print it, but I'd like a little bit more control options for which I am experimenting with the xtable package. However, I am really stuck with…
Psidom
  • 209,562
  • 33
  • 339
  • 356
12
votes
2 answers

xtable for conditional cell formatting significant p-values of table

I'm using xtable to generate tables to put in Latex, and was wondering if there's a way to have conditional formatting of cells so that all significant p-values are in grey? I'm using Knitr in TexShop. Here's an example using the diamonds data in…
dmt
  • 2,113
  • 3
  • 24
  • 23
11
votes
1 answer

Writing to file with xtable in R

I am using the xtable to produce tex output of a dataframe in R.3.3. Is there a way to write the output to a file? When I use it I am only able to obtain tex code in my R console.
splinter
  • 3,727
  • 8
  • 37
  • 82
11
votes
1 answer

xtable in R: Cannot get rid of row numbers

I have a dataframe in R that I create like this: estimate1 = rep(1,times=4) standardError = rep(2, times = 4) pvalue = runif(4, min=0, max=1) rowNames =c('Thing1','Things2','Thing3','Thing4') tableResults = as.data.frame(cbind(rowNames, estimate1,…
Eli
  • 280
  • 1
  • 3
  • 13
11
votes
1 answer

Knitr xtable row color result in 2nd table in the row header cell blacked out

Dear fellow R xtable and knitr users: I have been struggling with this problem for days now and I am very surprised there isn't a similar case reported by someone already. Your insight and help are greatly appreciated. I used xtable to make two or…
Jian Wang
  • 127
  • 8
1
2
3
26 27