This function prepares a data frame for summarization by handling missing data
based on the show_missing_data argument and applying the specified data manipulation
(DM) option to factor variables. It provides flexibility for data cleaning and ordering
before summarizing with functions like gtsummary.
prepare_table(
data1,
by_group = FALSE,
var_group = NULL,
drop_levels = TRUE,
freq_relevel = FALSE,
show_missing_data = TRUE
)A data frame that has been prepared based on the show_missing_data and DM arguments.
The function modifies the input data frame by applying labels, ordering factor variables,
and potentially dropping unused levels.
A data frame containing the data to be prepared.
A boolean (default is FALSE) to analyse by group.
The group variable (used to correctly update the label if needed).
Boolean (default = TRUE). Drop unused levels.
Boolean (default = FALSE). Reorder factors by frequency except for the group variable.
Should the missing data be displayed. Can be either :
FALSE: No missing data displayed
TRUE(default): Missing data displayed
The DM option defines the data manipulation to be applied to factor variables:
"tout": Both order factor levels and drop unused levels.
"tri": Only order factor levels.
"remove": Drop unused factor levels without ordering.
# Example usage with the iris dataset
prepare_table(iris)
Run the code above in your browser using DataLab