来自kable的add_header_above中不同的总列数

时间:2018-05-08 15:04:57

标签: r kableextra

我正在使用kableExtra格式化rmarkdown中的表格。在我的一个数据框中,我得到了一个奇怪的结果......

ncol(Selected)
Selected%>%
kable("html",format.args = list(decimal.mark = ".", big.mark = ","),caption = "Variables description  and data cleaning and treatment summary") %>%
add_header_above(c(" " = 2, "Kolmogorov-Smirnov" = 2, "Kruskall-Wallis" = 2, "Wilcoxon  Test"= 2)) %>%
kable_styling()

Selected对象是一个数据框,其维度为(256; 8)......

我明白了:

[1] 8
Error in htmlTable_add_header_above(kable_input, header, bold, italic, : The new header row you provided has a different total number of columns with the original kable output.

有什么问题?通过ncol,我确认对象Selected有8列...... 提前谢谢。

1 个答案:

答案 0 :(得分:2)

此数据框具有行名称。 kable命令将行名称计为列。算上这个,它起作用了。

Selected%>%
kable("html",format.args = list(decimal.mark = ".", big.mark = ","),caption = "Variables description  and data cleaning and treatment summary") %>%
add_header_above(c(" " = 3, "Kolmogorov-Smirnov" = 2, "Kruskall-Wallis" = 2, "Wilcoxon  Test"= 2)) %>%
kable_styling()