【发布时间】:2019-06-25 15:01:46
【问题描述】:
使用cell_spec 可以根据值有条件地格式化kable 表中的数字单元格,但是有没有办法根据字符串中的模式格式化单元格?
library(dplyr)
library(kableExtra)
df <- data.frame(x = c("bbb", "bba", "bbb"), y = c(-7, -7, 7)) %>%
mutate(x = cell_spec(x, "html", color = ifelse(grep("a", x), "red", "black"))) %>%
mutate(y = cell_spec(y, "html", color = ifelse(y < 0, "red", "black")))
kable(df, "html", escape = F) %>%
kable_styling("striped")
【问题讨论】: