Description Usage Arguments Value Author(s) See Also Examples
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
).
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])), ...)
|
data |
data set to be used. |
type |
print summary table for either |
variables |
character vector defining variables that should be included in the
table. Per default, all numeric or factor variables of |
variable.labels, labels |
labels for the variables. If |
group |
character specifying a grouping factor. Per default no grouping is applied. |
test |
logical or character string. If a |
colnames |
a vector of character strings of appropriate length.
The vector supplies alternative column names for the resulting
table. If |
digits |
number of digits to round to. For defaults see
|
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 |
sep |
logical. Determines whether separators (lines) should be added after
each variable. For defaults see |
sanitize |
logical (default: |
drop |
logical (default: |
show.NAs |
logical. Determines if NAs are displayed. Per default,
|
... |
additional arguments for |
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
.
Benjamin Hofner
For details see
summarize_numeric
and summarize_factor
.
Conversion to LaTeX tables can be done using
xtable.summary
and print.xtable.summary
.
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)
}
}
|
Loading required package: car
Loading required package: carData
Loading required package: xtable
Attaching package: 'papeR'
The following object is masked from 'package:utils':
toLatex
Loading required package: nlme
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
Loading required package: knitr
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}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.