Create Export Tables
xtable.RdConvert an R object to an xtable object, which can
then be printed as a LaTeX or HTML table.
Usage
xtable(x, caption = NULL, label = NULL, align = NULL, digits = NULL,
display = NULL, auto = FALSE, ...)Arguments
- x
An R object of class found among
methods(xtable). See below on how to write additional method functions forxtable.- caption
Character vector of length 1 or 2 containing the table's caption or title. If length is 2, the second item is the "short caption" used when LaTeX generates a "List of Tables". Set to
NULLto suppress the caption. Default value isNULL.- label
Character vector of length 1 containing the LaTeX label or HTML anchor. Set to
NULLto suppress the label. Default value isNULL.- align
Character vector of length equal to the number of columns of the resulting table, indicating the alignment of the corresponding columns. Also,
"|"may be used to produce vertical lines between columns in LaTeX tables, but these are effectively ignored when considering the required length of the supplied vector. If a character vector of length one is supplied, it is split asstrsplit(align, "")[[1]]before processing. Since the row names are printed in the first column, the length ofalignis one greater thanncol(x)ifxis adata.frame. Use"l","r", and"c"to denote left, right, and center alignment, respectively. Use"p{3cm}"etc. for a LaTeX column of the specified width. For HTML output the"p"alignment is interpreted as"l", ignoring the width request. Default depends on the class ofx.- digits
Numeric vector of length equal to one (in which case it will be replicated as necessary) or to the number of columns of the resulting table or matrix of the same size as the resulting table, indicating the number of digits to display in the corresponding columns. Since the row names are printed in the first column, the length of the vector
digitsor the number of columns of the matrixdigitsis one greater thanncol(x)ifxis adata.frame. Default depends on the class ofx. If values ofdigitsare negative, the corresponding values ofxare displayed in scientific format withabs(digits)digits.- display
Character vector of length equal to the number of columns of the resulting table, indicating the format for the corresponding columns. Since the row names are printed in the first column, the length of
displayis one greater thanncol(x)ifxis adata.frame. These values are passed to theformatCfunction. Use"d"(for integers),"f","e","E","g","G","fg"(for reals), or"s"(for strings)."f"gives numbers in the usualxxx.xxxformat;"e"and"E"given.ddde+nnorn.dddE+nn(scientific format);"g"and"G"putx[i]into scientific format only if it saves space to do so."fg"uses fixed format as"f", butdigitsas number of significant digits. Note that this can lead to quite long result strings. Default depends on the class ofx.- auto
Logical, indicating whether to apply automatic format when no value is passed to
align,digits, ordisplay. This ‘autoformat’ (based onxalign,xdigits, andxdisplay) can be useful to quickly format a typicalmatrixordata.frame. Default value isFALSE.- ...
Additional arguments. (Currently ignored.)
Details
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
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 passed to specify how the object x should be
manipulated. All method functions should return an object whose class
is c("xtable","data.frame"). The resulting object can
have attributes caption and label, but must have
attributes align, digits, and display.
Value
For most xtable methods, an object of class "xtable"
which inherits the data.frame class and contains several
additional attributes specifying the table formatting options.
Author
David Dahl dahl@stat.byu.edu with contributions and suggestions from many others (see source code).