I'm trying to format cell's within a column using cell_spec in the KableExtra library. My data and code looks like this:
df<-data.frame(Category=c("A","B","C","D"),Q1=c(46540.6541,4779.1654,798984.648,987454.144586),Q2=c(98742.06543,78993.0641,6418.016,48974.041684),QoQ=c("1.02%","8.05%","5.04","6.87"))
df$QoQ<-ifelse(
df$QoQ > 0.00,
cell_spec(df$QoQ, color = "green", bold = T),
cell_spec(df$QoQ, color = "red", bold = T))
kbl(df)
When I execute the code above, the table's QoQ column returns the following: <span style=" font-weight: bold; color: green !important;" >1.02%</span>. I suspect this is because I'm filtering the values numerically but my data class is character. My question is, can I keep my data as is, meaning I keep the % sign in the QoQ column, and still write a conditional statement where if the QoQ cell is greater than 0.00% then it is green, otherwise red?

