【问题标题】:different total number of columns in add_header_above from kable来自 kable 的 add_header_above 中不同的总列数
【发布时间】:2018-05-08 15:04:57
【问题描述】:

我正在使用 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()

所选对象是一个数据框,尺寸为 (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 列... 提前致谢。

【问题讨论】:

  • 如果不提供a minimal, reproducible example,您将无法获得任何具体建议
  • 嗨,大卫,感谢您关注我的问题。我同意这个问题没有最小的可重复示例,因为我没有提供数据框。你能告诉我我该怎么做吗?我在写问题的时候试过了,但我无法弄清楚......
  • 我想我找出了错误消息的原因......在试图更好地描述数据框(因为我无法附加它)时,我注意到这个数据框有行名,而其他人没有...我尝试将 add_header_above(c(" " = 2... 更改为 add_header_above(c(" " = 3...

标签: r kableextra


【解决方案1】:

这个数据框有行名。 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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-19
    • 2020-10-13
    • 1970-01-01
    • 2014-09-13
    • 1970-01-01
    • 2020-06-25
    • 2021-06-25
    • 2018-12-26
    相关资源
    最近更新 更多