我正在使用KableExtra
包来显示表格。我需要通过折叠行来显示数据框,还需要更改网格线的颜色。
使用的数据帧如下:
marksDF <- data.frame(
Staff = c("Henry","Henry","Clay","Clay","Clay","Clay","Clay","David","Jensen","Jensen","Jensen","Alex","Alex","Alex","Alex","Alex","Alex","Alex"),
Grade = c("9","10","11","11","12","12","8","9","9","9","9","9","9","9","9","9","10","11"),
Term1 = c("0","0","4","3","1","3","0","2","0","40","0","0","10","3","3","0","5","2"),
stringsAsFactors = FALSE
)
用于以表格格式显示数据框的代码为:
kable(marksDF, "html", booktabs = T, align = rep('c',2)) %>%
kable_styling(latex_options = "striped", stripe_color = "red") %>%
kableExtra::kable_styling(full_width = T) %>%
column_spec(1)%>%
collapse_rows(columns = 1:2) %>%
row_spec(1:2, align = "c", color = 'black')
获得的输出是:
期望的产出是每位员工的等级。但是,对于David,Jensen,Alex的员工来说,我正在升入9年级。
如何使用kableExtra软件包实现这一目标?