Description Usage Arguments Details Value Author(s) See Also Examples
The function produces LaTeX tables with summary statistics for continous variables. It makes use of the booktabs package in LaTeX to obtain tables with a nice layout.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | latex.table.cont(data, variables = names(data), labels = NULL, group = NULL,
colnames = NULL, digits = 2, table = c("tabular", "longtable"),
align = NULL, caption = NULL, label = NULL, floating = FALSE,
center = TRUE, sep = !is.null(group), sanitize = TRUE,
count = TRUE, mean_sd = TRUE, quantiles = TRUE,
incl_outliers = TRUE, drop = TRUE,
show.NAs = any(is.na(data[, variables])))
## S3 method for class 'table.cont'
print(x,
colnames = get_options(x, "colnames"),
table = get_options(x, "table"),
align = get_options(x, "align"),
caption = get_options(x, "caption"),
label = get_options(x, "label"),
floating = get_options(x, "floating"),
center = get_options(x, "center"),
sep = get_options(x, "sep"),
sanitize = get_options(x, "sanitize"),
count = get_options(x, "count"),
mean_sd = get_options(x, "mean_sd"),
quantiles = get_options(x, "quantiles"),
...)
|
data |
data set to be used |
variables |
character vector defining (continuous) variables that should be
included in the table. Per default, all non-factor variables of
|
labels |
labels for the variables. If |
group |
character specifying a grouping factor. Per default no grouping is applied. |
colnames |
a vector of character strings of length 9 (variable, N, standard
deviation, minimum, first quartile, median, third quartile and
maximum) or shorter if some of |
digits |
number of digits to round to. |
table |
character string. LaTeX table format, currently either
|
align |
character string. LaTeX alignment of table rows, per default
|
caption |
(optional) character string. Caption of LaTeX table. Note that captions are suported for all tables (see also details below). |
label |
(optional) character string. Label of LaTeX table specified as
|
floating |
logical (default: FALSE). Determines wether the table is a floating
object (i.e. use a |
center |
logical (default: TRUE). Determines if table should be centered. |
sep |
logical (default: TRUE if grouping specified, FALSE otherwise). Determines wether separators (lines) should be added after each variable. |
sanitize |
logical (default: TRUE) or a sanitizing function used to clean the
input in order to be useable in LaTeX environments. Per default
|
count |
(logical) indicator if number of complete cases ("n") should be included in the table (default: TRUE). |
mean_sd |
(logical) indicator if mean and standard deviation should be included in the table (default: TRUE). |
quantiles |
(logical) indicator if quantiles (including min and max) should be included in the table (default: TRUE). |
incl_outliers |
Per default we use |
drop |
logical (default: TRUE). Determines wether continuous variables, which contain only missing values are dropped from the table. |
show.NAs |
logical. Determines if the number of missings (NAs) is displayed as
a separate column. Per default, |
x |
An object of class |
... |
additional arguments for printing. Currently not used. |
The output requires \usepackage{booktabs}
in the LaTeX file.
Captions can be added to both, longtable
s and tabular
s.
In the latter case, captions are also suported if the table is no
floating object. In this case, the LaTeX package capt-of
is
required.
A special data.frame
with additional class table.cont
containing the computed statistics is returned from function
latex.table.cont
. Addtional attributes required for the print
function are contained (see attr(x, "latex.table.options")
).
These are extracted in the print function using the function
get_options
.
The output is printed with LaTeX style syntax highlighting to be used
e.g. in Sweave chunks with results=tex
.
Benjamin Hofner
latex.table.fac
and get_options
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ## Example requires package nlme to be installed and loaded
if (require("nlme")) {
## Use dataset Orthodont
data(Orthodont, package = "nlme")
## Get summary for continuous variables
latex.table.cont(Orthodont)
## Change statistics to display
latex.table.cont(Orthodont, quantiles = FALSE)
latex.table.cont(Orthodont, count = FALSE, quantiles = FALSE)
latex.table.cont(Orthodont, mean_sd = FALSE)
## Show column 'Missing' even if no missings are present
latex.table.cont(Orthodont, show.NAs = TRUE)
## Change variables to display
latex.table.cont(Orthodont, variables = "age")
## What happens in the display if we introduce some missing values:
set.seed(1907)
Orthodont$age[sample(nrow(Orthodont), 20)] <- NA
latex.table.cont(Orthodont)
## We can also have a look at the returned object:
df.cont <- latex.table.cont(Orthodont)
## Structure of object
str(df.cont)
## Make object a data.frame and have a look at the raw data
class(df.cont) <- "data.frame"
df.cont
print.table.cont(df.cont)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.