title: how to calculate the mean with conditions?
body: <p>Below is the script to generate a reproducible dataframe:</p>
  
  <pre><code>id &lt;- c(1:20)
  a &lt;- as.numeric(round(runif(20,-40,40),2))
  b &lt;- as.numeric(round(a*1.4+60,2))
  df &lt;- as.data.frame(cbind(id, a, b))
  </code></pre>
  
  <p>i would like to calculate the mean of "b" under different condition for "a".
  for example, what is the mean of "b" when -40 =&lt; a &lt; 0; and what is the mean of "b" when 0=&lt; a &lt;=40. </p>
  
  <p>Thank you very much!</p>