This function is similar to tbl_summary()
, but places summary statistics
wide, in separate columns.
All included variables must be of the same summary type, e.g. all continuous
summaries or all categorical summaries (which encompasses dichotomous variables).
Usage
tbl_wide_summary(
data,
label = NULL,
statistic = switch(type[[1]], continuous = c("{median}", "{p25}, {p75}"), c("{n}",
"{p}%")),
digits = NULL,
type = NULL,
value = NULL,
sort = all_categorical(FALSE) ~ "alphanumeric",
include = everything()
)
Arguments
- data
(
data.frame
)
A data frame.- label
(
formula-list-selector
)
Used to override default labels in summary table, e.g.list(age = "Age, years")
. The default for each variable is the column label attribute,attr(., 'label')
. If no label has been set, the column name is used.- statistic
(
character
)
character vector of the statistics to present. Each element of the vector will result in a column in the summary table. Default isc("{median}", "{p25}, {p75}")
for continuous summaries, andc("{n}", "{p}%")
for categorical/dichotomous summaries- digits
(
formula-list-selector
)
Specifies how summary statistics are rounded. Values may be either integer(s) or function(s). If not specified, default formatting is assigned viaassign_summary_digits()
. See below for details.- type
(
formula-list-selector
)
Specifies the summary type. Accepted value arec("continuous", "continuous2", "categorical", "dichotomous")
. If not specified, default type is assigned viaassign_summary_type()
. See below for details.- value
(
formula-list-selector
)
Specifies the level of a variable to display on a single row. The gtsummary type selectors, e.g.all_dichotomous()
, cannot be used with this argument. Default isNULL
. See below for details.- sort
(
formula-list-selector
)
Specifies sorting to perform for categorical variables. Values must be one ofc("alphanumeric", "frequency")
. Default isall_categorical(FALSE) ~ "alphanumeric"
.- include
(
tidy-select
)
Variables to include in the summary table. Default iseverything()
.
Examples
trial |>
tbl_wide_summary(include = c(response, grade))
Characteristic
n
%
trial |>
tbl_strata(
strata = trt,
~tbl_wide_summary(.x, include = c(age, marker))
)
Median
Q1, Q3
Median
Q1, Q3