summarize {papeR} | R Documentation |
Produce Summary Tables for Data Sets
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
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 |
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 |
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
.
Examples
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)
}
}