summarize: Produce Summary Tables for Data Sets

Description Usage Arguments Value Author(s) See Also Examples

Description

The function produces summary tables for factors and continuous variables. The obtained tables can be used directly in R, with LaTeX and HTML (by using the xtable function) or Markdown (e.g. by using the function kable).

Usage

1
2
3
4
5
6
summarize(data, type = c("numeric", "factor"),
    variables = names(data), variable.labels = labels, labels = NULL,
    group = NULL, test = !is.null(group), colnames = NULL,
    digits = NULL, digits.pval = 3, smallest.pval = 0.001,
    sep = NULL, sanitize = TRUE, drop = TRUE,
    show.NAs = any(is.na(data[, variables])), ...)

Arguments

data

data set to be used.

type

print summary table for either numeric or factor variables.

variables

character vector defining variables that should be included in the table. Per default, all numeric or factor variables of data are used, depending on type.

variable.labels, labels

labels for the variables. If variable.labels = NULL (default) variables is used as label. If variable.labels = TRUE, labels(data, which = variables) is used as labels. Instead of variable.labels one can also use labels.

group

character specifying a grouping factor. Per default no grouping is applied.

test

logical or character string. If a group is given, this argument determines whether a test for group differences is computed. For details see summarize_numeric and summarize_factor.

colnames

a vector of character strings of appropriate length. The vector supplies alternative column names for the resulting table. If NULL default names are used.

digits

number of digits to round to. For defaults see summarize_numeric and summarize_factor.

digits.pval

number of significant digits used for p-values.

smallest.pval

determines the smallest p-value to be printed exactly. Smaller values are given as “< smallest.pval”. This argument is passed to the eps argument of format.pval. See there for details.

sep

logical. Determines whether separators (lines) should be added after each variable. For defaults see summarize_numeric and summarize_factor.

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.

drop

logical (default: TRUE). Determines whether variables, which contain only missing values are dropped from the table.

show.NAs

logical. Determines if NAs are displayed. Per default, show.NAs is TRUE if there are any missings in the variables to be displayed (and FALSE if not). For details see summarize_numeric and summarize_factor.

...

additional arguments for summarize_numeric and summarize_factor. See there for details.

Value

A special data.frame with additional class summary containing the computed statistics is returned from function summarize. Addtional attributes required for the xtable.summary or print.xtable.summary function are contained as attributes. These are extracted using the function get_option.

Author(s)

Benjamin Hofner

See Also

For details see summarize_numeric and summarize_factor.

Conversion to LaTeX tables can be done using xtable.summary and print.xtable.summary.

get_option

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
if (require("nlme")) {
    ## Use dataset Orthodont
    data(Orthodont, package = "nlme")

    ## Get summary for continuous variables
    (tab1 <- summarize(Orthodont, type = "numeric"))

    ## Change statistics to display
    summarize(Orthodont, quantiles = FALSE, type = "numeric")
    summarize(Orthodont, quantiles = FALSE, count = FALSE, type = "numeric")
    summarize(Orthodont, mean_sd = FALSE, type = "numeric")

    ## Get summary for categorical variables
    (tab2 <- summarize(Orthodont, type = "fac"))

    ## use fraction instead of percentage
    summarize(Orthodont, percent = FALSE, type = "fac")

    ## Using the tables with Markdown
    if (require("knitr")) {
        kable(tab1)
        kable(tab2)
    }

    ## Using the tables with LaTeX
    if (require("xtable")) {
        xtable(tab1)
        ## grouped table
        xtable(summarize(Orthodont, group = "Sex"))
        xtable(tab2)
    }
}

hofnerb/papeR documentation built on March 31, 2021, 6:49 a.m.