table1_design {rifttable} | R Documentation |
Design A Descriptive Table
Description
This function generates a design
table from which
rifttable
can generate a descriptive table.
Usage
table1_design(
data,
...,
by = NULL,
total = TRUE,
empty_levels = FALSE,
na_always = FALSE,
na_label = "Unknown",
continuous_type = "median (iqr)",
binary_type = "outcomes (risk)"
)
Arguments
data |
Data set |
... |
Optional: Variables to include or exclude (using |
by |
Optional: Stratification variable. Typically the exposure. |
total |
Optional: Whether to add the total count at the beginning.
Defaults to |
empty_levels |
Optional: Whether to include empty levels of factor
variables. Defaults to |
na_always |
Optional: Whether to add the count of missing values for
each variable, even if there are none. Defaults to |
na_label |
Label for count of missing values. Defaults to
|
continuous_type |
Estimator ( |
binary_type |
Estimator ( |
Value
design
tibble that can be passed on to
rifttable
. Contains an attribute rt_data
so that the dataset does not have to be provided to
rifttable
another time.
Examples
# Data preparation
cars <- tibble::as_tibble(mtcars) |>
dplyr::mutate(
gear = factor(
gear,
levels = 3:5,
labels = c("Three", "Four", "Five")
),
# Categorical version of "hp", shows each category
hp_categorical = dplyr::if_else(
hp >= 200,
true = "200+ hp",
false = "<200 hp"
),
# Binary version of "hp", shows the TRUEs
hp_binary = hp >= 200
)
# Label some variables. Better alternative: labelled::set_variable_labels()
attr(cars$hp, "label") <- "Horsepower"
attr(cars$hp_categorical, "label") <- "Horsepower"
attr(cars$hp_binary, "label") <- "200+ hp"
attr(cars$am, "label") <- "Automatic transmission"
attr(cars$gear, "label") <- "Gears"
# Generate table "design"
design <- cars |>
table1_design(
hp, hp_categorical, hp_binary, mpg, am,
by = gear
)
# Use "design" to create a descriptive table.
design |>
rifttable(diff_digits = 0)
# Obtain a formatted table
design |>
rifttable(diff_digits = 0) |>
rt_gt()