# summarize: Produce Summary Tables for Data Sets In papeR: A Toolbox for Writing Pretty Papers and Reports

## 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

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

### Example output

Loading required package: car

Attaching package: 'papeR'

The following object is masked from 'package:utils':

toLatex

Factors are dropped from the summary
Factors are dropped from the summary
Factors are dropped from the summary
Factors are dropped from the summary
Non-factors are dropped from the summary
Non-factors are dropped from the summary
Factors are dropped from the summary
NOTE: Output requires \usepackage{booktabs} in your preamble.
\begin{center}
% latex table generated in R 3.4.4 by xtable 1.8-3 package
% Mon Dec 31 17:31:57 2018
\begin{tabular}{llrrr}
\toprule
& Level &   & N & \% \\
\cmidrule{2-2} \cmidrule{4-5}
Subject & M16 &  &   4 & 3.7 \\
& M05 &  &   4 & 3.7 \\
& M02 &  &   4 & 3.7 \\
& M11 &  &   4 & 3.7 \\
& M07 &  &   4 & 3.7 \\
& M08 &  &   4 & 3.7 \\
& M03 &  &   4 & 3.7 \\
& M12 &  &   4 & 3.7 \\
& M13 &  &   4 & 3.7 \\
& M14 &  &   4 & 3.7 \\
& M09 &  &   4 & 3.7 \\
& M15 &  &   4 & 3.7 \\
& M06 &  &   4 & 3.7 \\
& M04 &  &   4 & 3.7 \\
& M01 &  &   4 & 3.7 \\
& M10 &  &   4 & 3.7 \\
& F10 &  &   4 & 3.7 \\
& F09 &  &   4 & 3.7 \\
& F06 &  &   4 & 3.7 \\
& F01 &  &   4 & 3.7 \\
& F05 &  &   4 & 3.7 \\
& F07 &  &   4 & 3.7 \\
& F02 &  &   4 & 3.7 \\
& F08 &  &   4 & 3.7 \\
& F03 &  &   4 & 3.7 \\
& F04 &  &   4 & 3.7 \\
& F11 &  &   4 & 3.7 \\
\cmidrule{2-2} \cmidrule{4-5}
Sex & Male &  &  64 & 59.3 \\
& Female &  &  44 & 40.7 \\
\bottomrule
\end{tabular}
\end{center}


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