Creates publication-ready summary tables for categorical data grouped, by visit
Source:R/summaryByVisitCategorical.R
summaryByVisitCategorical.RdCreates publication-ready summary tables for categorical data grouped, by visit
Usage
summaryByVisitCategorical(
data,
vars = NULL,
group = NULL,
labels = NULL,
stat_cat = "n_percent",
visit = "visit",
order = NULL,
visitgroup = NULL,
digits_cat = 1,
missing_percent = TRUE,
missing = TRUE,
missing_text = "Missing",
add_n = FALSE,
overall = FALSE,
as_flex_table = FALSE,
border = TRUE,
word_output = FALSE,
file_path = paste0("SummaryByVisit_", format(Sys.Date(), "%Y%m%d"), ".docx")
)Arguments
- data
A data frame or tibble containing the data to be summarized.
- vars
Continuous variables to include in the summary table. Need to be specified with quotes, e.g.
"grade"orc("grade", "stage"). Default to all variables present in the data exceptgroup.- group
A single column from
data. Need to be specified with quotes, e.g."treatment". Summary statistics will be stratified according to this variable. Default to NULL. A maximum of 3 groups are currently supported.- labels
A list containing the labels that should be used for the variables in the table. If NULL, labels are automatically taken from the dataset. If no label present, the variable name is taken.
- stat_cat
Summary statistic to display for categorical variables. Options include "n", "n_N" and "n_percent" (default).
- visit
Name of the stratum for which summary statistics are displayed by line. Typically, this would be
"visit".- order
A numerical variable defining the visit order.
- visitgroup
A grouping variable for the stratum for which summary statistics are displayed by line. Must be an ordered factor. Typically, this would be a visit group such as e.g., baseline, follow-up etc.
- digits_cat
Digits for summary statistics of categorical variables. Default to 1.
- missing_percent
Indicates whether percentages for missings are shown (TRUE, default) or not (FALSE) for categorical variables. If "both", then both options are displayed next to each other.
- missing
Logical. If TRUE (default), the missing values are shown.
- missing_text
String indicating text shown on missing row. Default to "Missing".
- add_n
Logical. If TRUE, an additional column with the total number of non-missing observations for each variable is added.
- overall
Logical. If TRUE, an additional column with the total is added to the table. Ignored, if no groups are defined. Default to FALSE.
- as_flex_table
Logical. If TRUE (default) the gtsummary object is converted to a flextable object. Useful when rendering to Word.
- border
Logical. If TRUE, a border will be drawn around the table. Only available if flex_table = TRUE. Default is TRUE.
- word_output
Logical. If TRUE, the table is also saved in a word document.
- file_path
Character string. Specify the path of the Word document containing the table. Only used when
word_outputis TRUE. Needs to end with ".docx".