我正在尝试将符号*放在桌子内。到目前为止,我设法将符号放在标题和第一列中,但不在表格中。准确地说,我想标记某行或某列中所有小于固定值的值。你能帮我吗? 这是一个可重现的示例:
dt<- mtcars[,1:6]
dt_footnote <- dt
names(dt_footnote)[2] <- paste0(names(dt_footnote)[2],
footnote_marker_symbol(1))
row.names(dt_footnote)[4] <- paste0(row.names(dt_footnote)[4],
footnote_marker_alphabet(1))
kable(dt_footnote, align = "c",
escape = F) %>%
kable_styling(full_width = F) %>%
footnote(alphabet = "Footnote A; ",
symbol = "Footnote Symbol 1; ",
alphabet_title = "Type II: ", symbol_title = "Type III: ",
footnote_as_chunk = T)
这是我的尝试,但不起作用:
dt$disp<-ifelse(dt$disp<170,paste0(dt$disp,
footnote_marker_symbol(1)),dt$disp)
非常感谢!
答案 0 :(得分:1)
我无法复制您的示例,因为它在运行时会引发错误。但是这个例子应该可以工作
library(kableExtra)
library(dplyr)
dt <- mtcars[,1:6]
dt <- dt %>%
mutate(disp = case_when(
disp < 150 ~ paste0(as.character(disp), "*"),
TRUE ~ paste0(disp)
))
kable(dt, align = "c",
escape = F) %>%
kable_styling(full_width = F) %>%
footnote(alphabet = "Footnote A; ",
symbol = "Footnote Symbol 1; ",
alphabet_title = "Type II: ", symbol_title = "Type III: ",
footnote_as_chunk = T)