GT Summary "N" for continuous variables

Viewed 16

I would like to show the number of each continuous variable with gt summary install.packages("gtsummary") library(gtsummary)

This works perfect for categorical variables. Former code

trial2 %>%
  tbl_summary(
    by = trt,
    statistic = list(all_continuous() ~ "{mean} ({sd})",
                     all_categorical() ~ "{n} / {N} ({p}%)"),
    digits = all_continuous() ~ 2,
    label = grade ~ "Tumor Grade",
    missing_text = "(Missing)"
  )

New Code

trial2 %>%
  tbl_summary(
    by = trt,
    statistic = list(all_continuous() ~ "{mean} ({sd} {N})",
                     all_categorical() ~ "{n} / {N} ({p}%)"),
    digits = all_continuous() ~ 2,
    label = grade ~ "Tumor Grade",
    missing_text = "(Missing)"
  )

gives me:

x There was an error calculating the summary statistics for "all_continuous()". Is this variable's class supported by `mean`, `sd`, and `N`?
Error in `mutate()`:
! Problem while computing `df_stats = pmap(...)`.
Caused by error in `abort()`:
! `message` must be a character vector, not a <rlang_error/error/condition> object.
Backtrace:
  1. ... %>% bold_labels()
 26. gtsummary:::safe_summarise_at(., variable = variable, fns = fns)
 27. base::tryCatch(...)
 28. base (local) tryCatchList(expr, classes, parentenv, handlers)
 29. base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 30. value[[3L]](cond)
 31. rlang::abort(message = e)

Is there a way to calcuate the "N" for continuous variables?

Thanks in advance

0 Answers
Related