如何使用 kableExtra 为一个单元格着色

How to color one cell with kableExtra

我只是想用 kableExtra 突出显示 table 中的一个单元格。我遇到的问题是我的一些单元格有 $s 和 ()s。这是它的样子

df3 <- data.frame(
  "Bitcoin Price:" = c("Snow Panther B1+", "ASICminer 8 nano", "S9", "Avalon 921", "Dragonmint T1", "Edit E11++"), 
  "3000" = c("(0.71)", "(76.85)", "(5.80)", "(0.81)", "(08.14)", "(35.42)"),
  "6000" = c("50.37", "(04.31)", "6.06", "7.62", "(5.39)", "37.12"), 
  "9000" = c("71.44", "68.24", "47.92", "26.04", "7.35", "09.66"),
  stringsAsFactors = FALSE, check.names=FALSE)

我已经试过了,但是没用

df3 %>%
  mutate(
    `6000`[,2] = cell_spec(`6000`[,2], color = "red", bold = T)
  ) %>%
  select("Bitcoin Price:", everything()) %>%
  kable(align = "c", escape = F) %>%
  kable_styling("hover", "striped", full_width = F)  %>%
  add_header_above(c(" " = 1, "Current Difficulty" = 3)) %>%
  add_footnote(c("Statistics Calculated 2019"), notation = "symbol")

有人有什么建议吗?我觉得我很亲近。我正在尝试使单元格的值为 ($1004.31),红色。

这是您要找的吗?

df3 %>%
  mutate(`6000` = cell_spec(`6000`, "html",color = ifelse(`6000` == "(04.31)", "red", "grey"))) %>%
  select("Bitcoin Price:", everything()) %>%
  kable(align = "c", escape = F) %>%
  kable_styling("hover", "striped", full_width = F)  %>%
  add_header_above(c(" " = 1, "Current Difficulty" = 3)) %>%
  add_footnote(c("Statistics Calculated 2019"), notation = "symbol")