Skip to content

cols_merge: Add NA handling with custom pattern #1010

Answered by rich-iannone
alex-lauer asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Alex,

Sorry about the difficulty encountered here. Right now the pattern argument doesn't allow for more expressive arrangements of text that account for NA values (this is something that is on my radar). However, we can perform a more manual solution with text_transform(). Here is what I wrote:

library(gt)
library(tidyverse)

tbl <- tibble(label = c("n" ,"Mean", "95% CI", "Min - Max"),
              trt_n = c(15, 14, rep(NA, 2)),
              trt_ci_low = c(rep(NA, 2), 10, NA),
              trt_ci_up = c(rep(NA, 2), 18, NA),
              trt_min = c(rep(NA, 3), 4),
              trt_max = c(rep(NA, 3), 20))

tbl %>% 
  gt() %>% 
  sub_missing(missing_text = "") %>%
  text_transform…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@alex-lauer
Comment options

Answer selected by alex-lauer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants