Hello everybody,
I wolud like to print follow data frame to excel with a conditional cells print.I have this data frame:
df <- data.frame(id = sample(1:100, 20, replace = TRUE),
inputval = sample(seq(0, 1, by=0.01), 20, replace = TRUE),
outcome = sample(1:4, 20, replace = TRUE))
And I would like to get the same data frame whit elements of column "id" red painted depends on this condition:
If inputval*outcome>2 then i would like to print the cell of "Id" with red colour in xlsx.
For example, the inputval[2]*outcome[2]=2.22 so I would like that the cell of Id[2]=72 be painted in the xlsx.
I have tried the "openxlsx" package:
conditionalFormatting(wb, "Sheet", cols = ncol(df),
rows = nrow(df), rule = "#", style = warm1Style,
type = "contains")
but i can't put a function in a "rule" parametre to identify the "Id" to paint with:
saveWorkbook(wb, file, overwrite = TRUE)
Thank you in advance!