title: Sum object in a column between an interval defined by another column
body: <p>I have a data frame like this:</p>
  
  <pre><code>  df
         A B
   [1,]  1 4
   [2,]  2 3
   [3,]  3 5
   [4,]  4 7
   [5,]  5 5
   [6,]  6 7
   [7,]  7 4
   [8,]  8 7
   [9,]  9 3
  [10,] 10 7
  </code></pre>
  
  <p>I need to sum the numbers in column B that fall between a certain interval defined by column A. For example sum the value in B between A≥1 and A&lt;3.</p>
  
  <p>I'm trying to use this:</p>
  
  <pre><code>&gt; sum(which(df$B[df$A&gt;=1] &amp; df$B[df$A&lt;3]))
  </code></pre>
  
  <p>but it does not give me what I want.</p>