summarize_factor: Produce Summary Tables for Data Sets

Description Usage Arguments Value Author(s) See Also Examples

View source: R/summarize.R

Description

The function produces summary tables for factor 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
7
8
9
summarize_factor(data,
    variables = names(data), variable.labels = labels, labels = NULL,
    group = NULL, test = !is.null(group), colnames = NULL,
    digits = 3, digits.pval = 3, smallest.pval = 0.001,
    sep = TRUE, sanitize = TRUE, drop = TRUE,
    show.NAs = any(is.na(data[, variables])),
    ## additional specific arguments
    percent = TRUE, cumulative = FALSE,
    na.lab = "<Missing>", ...)

Arguments

data

data set to be used.

variables

variables that should be included in the table. For details see summarize.

variable.labels, labels

labels for the variables. For details see summarize.

group

character specifying a grouping factor. For details see summarize.

test

logical or charachter specifying test for group differences. For details see summarize.

colnames

a vector of character strings of appropriate length. For details see summarize.

digits

number of digits to round to (only used for fractions). Per default all values are rounded to three digits.

digits.pval

number of significant digits used for p-values.

smallest.pval

determines the smallest p-value to be printed exactly. For details see summarize.

sep

logical (default: TRUE). Determines whether separators (lines) should be added after each variable.

sanitize

logical (default: TRUE) or a sanitizing function. For details see summarize.

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 as a separate category for each factor variable with missings. If TRUE, an additional statistic which includes the missings is displayed (see Examples). Per default, show.NAs is TRUE if there are any missings in the variables to be displayed (and FALSE if not).

percent

logical. Should the fractions be given as percent values? Otherwise, fractions are given as decimal numbers.

cumulative

logical. Should cumulative fractions be displayed?

na.lab

label for missing values (default: "<Missing>").

...

additional arguments. Currently not used.

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 link{summarize} and link{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
## Example requires package nlme to be installed and loaded
if (require("nlme")) {
    ## Use dataset Orthodont
    data(Orthodont, package = "nlme")

    ## Get summary for continuous variables
    summarize(Orthodont, type = "factor")

    ## Reorder data for table:
    summarize(Orthodont, variables = c("Sex", "Subject"), type = "factor")

    ## What happens in the display if we introduce some missing values:
    set.seed(1907)
    Orthodont$Sex[sample(nrow(Orthodont), 20)] <- NA
    summarize(Orthodont, type = "factor")
    summarize(Orthodont, variables = "Sex", type = "factor")
    ## do not show statistics on missing values
    summarize(Orthodont, variables = "Sex", show.NAs = FALSE, type = "factor")
}

papeR documentation built on March 23, 2021, 1:08 a.m.