title: How to color specific cells in a Data Frame / Table in R?
body: <p>I would like to color specific cells in the following dataframe. For example, in the inputval column, I would like to highlight cells in the range of <code>[0.8, 0.9)</code> magenta, and the cells in that same column in the range of <code>[0.7, 0.8)</code> blue. Similarly, I'd like the output column cells with a value of 1 to be colored magenta and those with value 4 to be colored blue. For the rest of the cells in the dataframe, I would like them to remain white.  </p>
  
  <p>I have the following reproducible code which highlights by row only, and limits me to coloring in magenta and white only. How can I add another color and do so by cell?</p>
  
  <pre><code>set.seed(123)
  df &lt;- 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))
  
  cols &lt;- with(df, ifelse(outcome == 1, 'magenta', 'white'))
  
  library('htmlTable')
  htmlTable(as.matrix(df), col.rgroup = cols)
  </code></pre>
  
  <p>I realize that the issue for adding different colors is with the <code>ifelse</code> call in <code>with</code> that limits me to just magenta and white. How can I add another condition here? </p>
  
  <p>While I know what's causing the multiple color issue, I'm pretty clueless about how to color only specific cells.  </p>
  
  <p>This is the same example as <a href="https://stackoverflow.com/questions/27114926/r-conditional-row-highlighting-in-html-table-created-using-xtable-or-kable">the accepted answer to this question</a>.
   Thanks!</p>