latex_table_cont: Produce (LaTeX) Summaries for Continuous Variables

Description Usage Arguments Details Value Author(s) See Also Examples

Description

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.

Usage

 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"),
      ...)

Arguments

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 data are used.

labels

labels for the variables. If labels = NULL (default) variables is used as label. If labels = TRUE, labels(data, which = variables) is used as labels.

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 count, mean_sd or quantiles is FALSE. The vector supplies alternative column names for the resulting LaTeX table. If NULL default names are used.

digits

number of digits to round to.

table

character string. LaTeX table format, currently either "tabular" (default) or "longtable".

align

character string. LaTeX alignment of table rows, per default "lr...r", where "r" is repeated ncol - 1 times.

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 \label{"label"}.

floating

logical (default: FALSE). Determines wether the table is a floating object (i.e. use a table environment or not). Note that a longtable cannot be a floating object but captions can be used.

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 toLatex.character is used.

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 fivenum to compute the quantiles (if quantiles = TRUE). If extreme values should be excluded from min/max in the table, boxplot( , plot = FALSE)$stats is used instead.

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, show.NAs is TRUE if there are any missings in the variables to be displayed (and FALSE if not).

x

An object of class table.fac. See Value for details.

...

additional arguments for printing. Currently not used.

Details

The output requires \usepackage{booktabs} in the LaTeX file.

Captions can be added to both, longtables and tabulars. 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.

Value

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.

Author(s)

Benjamin Hofner

See Also

latex.table.fac and get_options

Examples

 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)
}

papeR documentation built on May 2, 2019, 4:55 p.m.