display and merge table by a separator

I Have two summaries and i am trying to display table as one but the aggregation to be display by separator . trying to create a function by which I can display single table for two summaries.


dataset <- mtcars
var1 <- "mpg"
var2 <- "disp"


var1 <- rlang::parse_expr(var1)
var2 <- rlang::parse_expr(var2)


summ_tab1<- dataset %>% filter(!is.na(!!var1)) %>%   summarise(
  Median = round(quantile(!! var1, type=6, probs = seq(0, 1, 0.25), na.rm=TRUE)[3],digits = 0),
  total = sum(!is.na(!!var1)))


summ_tab2<- dataset %>% filter(!is.na(!!var2)) %>%   summarise(
  Median = round(quantile(!! var2, type=6, probs = seq(0, 1, 0.25), na.rm=TRUE)[3],digits = 0),
  total = sum(!is.na(!!var2)))

the output should be look like below

Median total
19 ; 196 32 ; 32
dataset %>% 
  summarise(
    Median = paste(
      round(quantile(!!var1, type = 6, 0.5, na.rm = TRUE), digits = 0), 
      round(quantile(!!var2, type = 6, 0.5, na.rm = TRUE), digits = 0), 
      sep = " ; "
    ), 
    total = paste(
      sum(!is.na(!!var1)), 
      sum(!is.na(!!var2)), 
      sep = " ; "
    )
  )

its working now Thanks, why didn't i get the same logic but anyways , Thanks alot

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.