cross_tbl {pubh} | R Documentation |
Table of descriptive statistics by categorical variable.
Description
cross_tbl
is a wrapper to function from package tbl_summary
that constructs tables of descriptive statistics stratified by levels of a categorical outcome.
Usage
cross_tbl(
data,
by,
head_label = " ",
bold = TRUE,
show_total = TRUE,
p_val = FALSE,
pad = 3,
method = 2,
...
)
Arguments
data |
A data frame where the variables in the |
by |
The quoted name of the categorical variable (factor) used for the stratification. |
head_label |
Character, label to be used as head for the variable's column. |
bold |
Display labels in bold? |
show_total |
Logical, show column with totals? |
p_val |
Logical, show p-values? |
pad |
Numerical, padding above and bellow rows. |
method |
An integer indicating methods for continuous variables. 1 Reports means and standard deviations. 2 Reports medians and interquartile ranges. |
... |
Additional arguments passed to |
Details
Function cross_tbl
is a relatively simple wrapper to function tbl_summary
. It constructs contingency tables and can also be used to report a table with descriptives for all variables stratified by one of the variables. Please see examples to see how to list variables. If data is labelled, the label of the stratifying variable is used as part of the header.
Value
A huxtable with descriptive statistics stratified by levels of the outcome.
See Also
Examples
require(dplyr, quietly = TRUE)
#' data(Oncho)
## A two by two contingency table:
Oncho %>%
select(mf, area) %>%
cross_tbl(by = "mf", bold = TRUE) %>%
theme_pubh(2)
## Reporting prevalence:
Oncho %>%
select(mf, area) %>%
cross_tbl(by = "area", bold = TRUE) %>%
theme_pubh(2)
## Descriptive statistics for all variables in the \code{Oncho} data set except \code{id}.
Oncho %>%
select(-id) %>%
cross_tbl(by = "mf", bold = TRUE) %>%
theme_pubh(2)