tbl_cross | R Documentation |
The function creates a cross table of two categorical variables.
tbl_cross(
data,
row = NULL,
col = NULL,
label = NULL,
statistic = NULL,
digits = NULL,
percent = c("none", "column", "row", "cell"),
margin = c("column", "row"),
missing = c("ifany", "always", "no"),
missing_text = "Unknown",
margin_text = "Total"
)
data |
A data frame |
row |
A column name in |
col |
A column name in |
label |
List of formulas specifying variables labels,
e.g. |
statistic |
A string with the statistic name in curly brackets to
be replaced with the numeric statistic (see glue::glue).
The default is |
digits |
Specifies the number of decimal
places to round the summary statistics. By default integers are shown
to the zero decimal places, and percentages are formatted with |
percent |
Indicates the type of percentage to return.
Must be one of "none", "column", "row", or "cell". Default is "cell" when
|
margin |
Indicates which margins to add to the table.
Default is |
missing |
Indicates whether to include counts of |
missing_text |
String to display for count of missing observations.
Default is |
margin_text |
Text to display for margin totals. Default is |
A tbl_cross
object
Example 1
Example 2
Karissa Whiting, Daniel D. Sjoberg
Review list, formula, and selector syntax used throughout gtsummary
Other tbl_cross tools:
add_p.tbl_cross()
,
inline_text.tbl_cross()
# Example 1 ----------------------------------
tbl_cross_ex1 <-
trial %>%
tbl_cross(row = trt, col = response) %>%
bold_labels()
# Example 2 ----------------------------------
tbl_cross_ex2 <-
trial %>%
tbl_cross(row = stage, col = trt, percent = "cell") %>%
add_p() %>%
bold_labels()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.