The function produces objects which can be printed to LaTeX and HTML code.
# S3 method for summary
xtable(x, caption = NULL, label = NULL, align = NULL,
digits = NULL, display = NULL, ...)# S3 method for xtable.summary
print(x, rules = NULL, header = NULL,
caption.placement = getOption("xtable.caption.placement", "top"),
hline.after = getOption("xtable.hline.after", NULL),
include.rownames = FALSE,
add.to.row = getOption("xtable.add.to.row", NULL),
booktabs = getOption("xtable.booktabs", TRUE),
sanitize.text.function = get_option(x, "sanitize"),
math.style.negative = getOption("xtable.math.style.negative", TRUE),
math.style.exponents = getOption("xtable.math.style.exponents", TRUE),
tabular.environment = getOption("xtable.tabular.environment", "tabular"),
floating = getOption("xtable.floating", FALSE),
latex.environments = getOption("xtable.latex.environments", c("center")),
...)
After printing, a table with LaTeX markup is returned.
object of class "summary", which is produced by the
function summarize or an object of class
"xtable.summary" produced by xtable.
character vector specifying the table's caption; see
xtable for details.
character string specifying the LaTeX label or HTML anchor; see
xtable for details.
character string specifying the alignment of table columns; see
xtable for details.
numeric vector specifying the number of digits to display in each
column; see xtable for details.
character string specifying the column types; see
xtable for details.
character string specifying the rules to be used. Per default the
rules are defined by summarize and subsequently
extracted from x via get_option(x, "rules").
character string specifying the table header to be used. Per default the
header is defined by summarize and subsequently
extracted from x via get_option(x, "header").
can be either "bottom" or "top" (default). Note that
the standard default of print.xtable
is "bottom".
vector indicating the rows after which a horizontal line is printed.
Here, the default is to not draw hlines (i.e. hline.after =
NULL) and horizontal lines are added via add.to.row
(see there for details). Note that the standard default of
print.xtable is c(-1,0,nrow(x)).
list of row numbers (pos) and text (command) to be
added to the specified rows. Per default, top and bottom rules are
added to the table and a rule specified in rules is added
below the heading. If sep = TRUE in summarize
additional separators (as specified in rules) are added after
each variable.
logical. Always set to FALSE.
logical. If TRUE (default), the toprule,
midrule and bottomrule tags from the LaTeX package
"booktabs" are used rather than hline for the
horizontal line tags. Note that the standard default of
print.xtable is FALSE.
All non-numeric enteries (except row and column names) are sanitised
in an attempt to remove characters which have special meaning for
the output format. Per default the function toLatex is
used to sanitize the text. For more options see
print.xtable.
logical. If TRUE (default) the negative sign is wrapped in
dollar signs for LaTeX tables. Note that the standard default of
print.xtable is FALSE.
logical. If TRUE (default) scientific numers are set as
exponents. See print.xtable for details.
Note that the standard default of print.xtable
is FALSE.
character string. Per default "tabular" is used. For long
tables that span over more than one page, one can use
"longtable". For more options see
print.xtable.
logical. Determine if the table is printed in a floating
environment. Note that the standard default of
print.xtable is TRUE. See there for
details.
character string. Per default "center" is used. In contrast
to the default behavior of print.xtable,
tables are also centered if no floating environment is used. For
details and more options see print.xtable.
additional arguments passed to xtable or
print.xtable. See there for details.
Benjamin Hofner
We use the standard xtable function but add a special class
that allows different defaults in the print.xtable function.
In general, all options of print.xtable can be used as well as
global options set via options(). E.g.
options(xtable.booktabs = FALSE
will set the argument booktabs per default to
FALSE for all calls to print.xtable.
For details see xtable and
print.xtable.
summarize, get_option
if (require("nlme")) {
## Use dataset Orthodont
data(Orthodont, package = "nlme")
## Get summary for continuous variables
(tab1 <- summarize(Orthodont, type = "numeric"))
## Get summary for categorical variables
(tab2 <- summarize(Orthodont, type = "fac"))
## Using the tables with LaTeX
if (require("xtable")) {
xtable(tab1)
## grouped table
xtable(summarize(Orthodont, group = "Sex"))
xtable(tab2)
}
}
Run the code above in your browser using DataLab