kableExtra: Put a few rows of a table into many categories programmatically

947 views Asked by At

Currently kableExtra 0.5.1 only supports Put a few rows of a table into one category. I wonder if there is any tweak to Put a few rows of a table into many categories programmatically like group_rows(kable_input = x, group_label = c("Group 1", "Group 2"), start_row = c(1, 5), end_row = c(2, 6)). Thanks

library(knitr)
library(kableExtra)

x <- knitr::kable(head(mtcars, 10), "latex")
kableExtra::group_rows(kable_input = x, group_label = c("Group 1", "Group 2"), start_row = c(1, 5), end_row = c(2, 6))
1

There are 1 answers

2
Hao On BEST ANSWER

With dev version of kableExtra, you can use the index option to group rows in a similar way with add_header_above().

kable(mtcars[1:10, 1:5], "latex", booktabs = T) %>%
  group_rows(index = c(" " = 3, "Group 1" = 3, "Group 2" = 4))