kableExtra:以编程方式将 table 的几行放入多个类别

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

目前kableExtra 0.5.1只支持将table的几行归为一类。我想知道是否有任何调整可以像 group_rows(kable_input = x, group_label = c("Group 1", "Group 2"), start_row = c(1, 5), end_row = c(2, 6)) 这样以编程方式将 table 的几行放入许多类别中。谢谢

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))

对于 kableExtra 的开发版本,您可以使用 index 选项以类似于 add_header_above().

的方式对行进行分组
kable(mtcars[1:10, 1:5], "latex", booktabs = T) %>%
  group_rows(index = c(" " = 3, "Group 1" = 3, "Group 2" = 4))