【发布时间】:2018-02-24 19:20:41
【问题描述】:
如果单元格的值大于80,我需要为单元格着色。例如,给定这个名为df的数据框:
dput(df)
structure(list(Server = structure(1:2, .Label = c("Server1",
"Server2"), class = "factor"), CPU = c(79.17, 93), UsedMemPercent = c(16.66,
18.95)), .Names = c("Server", "CPU", "UsedMemPercent"), row.names = c(NA,
-2L), class = "data.frame")
df[2,2] 应该是红色的。我可以使用 xtable 来更改文本的颜色:
df[, 2] = ifelse(df[, 2] > 80, paste("\\color{red}{", round(df[, 2], 2), "}"), round(df[, 2], 2))
如果我这样做并用 kable 打印出表格,它不会打印出来。任何想法如何为 kable 输出表中的单元格着色?
【问题讨论】:
标签: r knitr conditional-formatting kable