title: Conditional formatting based on value in first row of a datatable in R
body: <p>I have the following dataframe:</p>
  
  <pre><code>df &lt;- data.frame(
  id = LETTERS[1:10],
  score1 = c(30, 45, 30, 28, 33, 29, 27, 27, 31, 30),
  score2 = c(40, 27, 30, 28, 47, 29, 27, 51, 31, 30))
  
  df
     id score1 score2
  1   A     28     28
  2   B     27     27
  3   C     30     30
  4   D     28     28
  5   E     29     29
  6   F     29     29
  7   G     27     27
  8   H     27     27
  9   I     31     31
  10  J     30     30
  </code></pre>
  
  <p>Is there a way to use conditional formatting to change the colour of the output based on a comparison with the value in the first row?
  Specifically, I would like all of the values in the score1 and score2 columns to be red if the score is higher than the value in the first row and green if the score is lower than the value in the first row.</p>
  
  <p>So for score1, values are compared to 30:
  These values should be red: 45, 33, 31.
  These values should be green: 28, 29, 27, 27</p>
  
  <p>For score 2, values are compared to 40:
  These values should be red: 47, 51.
  These values should be green: 27, 30, 28, 29, 27, 31, 30.</p>