From dd8dacb3b58ff89c025a215b4b0f4d8a58f7aa09 Mon Sep 17 00:00:00 2001 From: Emilylyu99 Date: Sun, 2 Jun 2024 21:09:35 -0600 Subject: [PATCH] Update metalite_table1.R Handling missing value when group contain missing values --- R/metalite_table1.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/R/metalite_table1.R b/R/metalite_table1.R index 002f267..6aae286 100644 --- a/R/metalite_table1.R +++ b/R/metalite_table1.R @@ -61,6 +61,19 @@ metalite_table1 <- function(formula, data[[group]] <- factor(data[[group]]) + if (missing_group == "ignore") { + data <- data[!is.na(data[[group]]), ] + message("Ignore missing values in the group variable.") + } else if (missing_group == "count") { + data[[group]] <- addNA(data[[group]], ifany = TRUE) + levels(data[[group]]) <- c(levels(data[[group]]), "Missing") + } else if (missing_group == "display") { + data[[group]] <- addNA(data[[group]], ifany = TRUE) + levels(data[[group]]) <- c(levels(data[[group]]), "Missing") + } else { + stop("Invalid value for 'missing_group'.") + } + var_label <- metalite::get_label(data)[var] plan <- metalite::plan(