title: get average column A based on a range of values in column B
body: <p>My dataframe has several columns as follows:</p>
  
  <pre><code>df1 &lt;- data.frame(A = c(1,2,4), B=c(1,3,1), C=c(1,1,3))
  </code></pre>
  
  <p>I have two conditions to get average values for column A.</p>
  
  <ul>
  <li>Condition 1: I want to get average of column A when B is 1, i.e. only row1 and row2 will be averaged.</li>
  <li>Condition 2: I want to get average of column B when column A's values are larger than 1 but smaller than 3, i.e. only row 2 will be considered.</li>
  </ul>
  
  <p>I know I can use filter to cut the dataframe to have column B = 1 only.  However, I am unsure how to do it when I want the column B to be considered as a range within 1 and 3.</p>
  
  <p>Are there any smarter ways to get the average values of column without cutting the dataframe into a smaller size first?</p>