给定一个小数据集如下:
library(gt)
library(tidyverse)
id <- c(1,2,3,4,5)
res1 <- c("true", "true", "false", "true", "false")
res2 <- c("false", NA, NA, "true", "true")
df <- data.frame(id, res1, res2)
df %>%
gt()
出去:
对于列res1
和res2
,假设值内容为true
s,我需要用red
背景颜色突出显示该单元格,如果false
是s,用green
颜色突出显示,对于其他情况,保持它们的颜色为原始颜色。
我如何在 R 中使用 gt 包来实现这一点?
注意:下面链接中的示例代码和结果适用于values,而不是这种情况下的字符串。
参考: