I have a dataframe (mtcars). It has columns with names: mpg cyl disp hp drat wt qsec vs I want to compare each column with vs ( column 1 vs column 8, column 2 vs column 8 and etc) and colour each column from 1: 7 as red (if the element is less than that of one in column8), yellow (if equal) or green (if greater).
I have used KableExtra package and used the below code:
library(dplyr)
library(kableExtra)
mtcars %>%
mutate(
car = row.names(.),
mpg = cell_spec(mpg, "html", background = ifelse(mpg > vs, "green", "red")),
cyl = cell_spec(cyl, "html", background = ifelse(cyl > vs,"green", "red" )),
) %>%
kable(format = "html", escape = F) %>%
kable_styling("striped", full_width = F)
I could achieve somehow but have two major issues:
KableExtra does not produce cell background as a tile/fill in Html it just highlights text in cell. I see latex can produce cell background but I can not use latex need only html solution.
In my actual data frame there are 70 dynamic columns and therefore need to access columns without names.
Tried with condformat and tableHTML too...but could not achieve comparing columns dynamically.