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

时间:2017-09-11 13:25:10

标签: r knitr kableextra kable

目前kableExtra 0.5.1仅支持将表格的几行放入一个类别。我想知道是否有任何调整将表格中的几行放入多个类别,如group_rows(kable_input = x, group_label = c("Group 1", "Group 2"), start_row = c(1, 5), end_row = c(2, 6))。感谢

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 个答案:

答案 0 :(得分:1)

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