How to add grand totals in RMarkdown Kable object in R? [code & images included]

1.7k Views Asked by At

I currently have two side by side tables in an Rmarkdown file. See below. I want to add a totals row for the right column from the two data frames.

enter image description here

I am currently doing the following to make these two tables appear side by side when I knit my file to html

tr::kables(list(
  kable(caption = "Promise Day Distribution", align=rep('l', 5),
    step1_fix %>% 
  group_by(days) %>% 
  summarise(Orders = n_distinct(ID))
    ) %>% kable_styling(),
    kable(caption = "Delivery Day Distribution", align=rep('l', 5),
    step1_fix %>% 
       adorn_totals("row") %>% 
  group_by(days) %>% 
  summarise(Orders = n_distinct(ID))
    ) %>% kable_styling()
    
  )
) %>% kable_styling()

How can I add grand totals into the code above? I tried to use adorn_totals() but I was recieving errors

2

There are 2 best solutions below

0
On BEST ANSWER

I tried the adorn_totals() to apped total row and column. Worked perfect (https://rdrr.io/cran/janitor/man/adorn_totals.html)

0
On

the function adorn_totals() appears to be in the janitor package, have you installed and loaded that package into R, alongside kable? try loading the library and rerunning your code.