Learn R Programming

RastaRocket (version 1.0.2)

prepare_table: Prepare a Data Frame for Summarization with Custom Missing Data Handling and Factor Ordering

Description

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.

Usage

prepare_table(
  data1,
  by_group = FALSE,
  var_group = NULL,
  drop_levels = TRUE,
  freq_relevel = FALSE,
  show_missing_data = TRUE
)

Value

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.

Arguments

data1

A data frame containing the data to be prepared.

by_group

A boolean (default is FALSE) to analyse by group.

var_group

The group variable (used to correctly update the label if needed).

drop_levels

Boolean (default = TRUE). Drop unused levels.

freq_relevel

Boolean (default = FALSE). Reorder factors by frequency except for the group variable.

show_missing_data

Should the missing data be displayed. Can be either :

  • FALSE: No missing data displayed

  • TRUE(default): Missing data displayed

Details

  • 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.

Examples

Run this code
# Example usage with the iris dataset
prepare_table(iris)

Run the code above in your browser using DataLab