如何格式化表格中的特定条目?

问题描述 投票:0回答:1

我表的第一列包含一些名称。由向量定义。我需要显示输出表并突出显示(例如,使用粗体字符或其他颜色)特定名称。要突出显示的名称在另一个向量中定义。

这是我的代码:

'''r

df<-cbind(1:5,6:10,11:15)
df<-as.data.frame(df)
Risk<-c("Equity","FX","IR","Issuer","Credit") # first column in the table
df<-cbind(Risk,df)# final table
hnames<-c("FX","IR") # names to be highlighted in the first column of the
                     # table
```           

总之,我想强调“风险”和“ hnames”向量之间的共同元素。预先感谢您的答复。

r
1个回答
0
投票

尝试使用格式表

formattable(df, list(
     Risk= formatter("span",style = ~ style(color=ifelse(Risk %in% hnames, "grey", NA), font.weight = ifelse(Risk %in% hnames, "bold", NA)))))

© www.soinside.com 2019 - 2024. All rights reserved.