summarize_factor {papeR} | R Documentation |
Produce Summary Tables for Data Sets
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
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 |
variable.labels , labels |
labels for the variables.
For details see |
group |
character specifying a grouping factor.
For details see |
test |
logical or charachter specifying test for group differences.
For details see |
colnames |
a vector of character strings of appropriate length.
For details see |
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 |
sep |
logical (default: |
sanitize |
logical (default: |
drop |
logical (default: |
show.NAs |
logical. Determines if NAs are displayed as a separate category for
each factor variable with missings. If |
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: |
... |
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
.
Examples
## 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")
}