title: Use two columns as index to calculate a third column
body: <p>I have one vector</p>
  
  <pre><code>&gt;a&lt;-c(4,5,6,7,8)
  </code></pre>
  
  <p>I have one data.frame</p>
  
  <pre><code>&gt;df&lt;-data.frame(start=c(1,4),end=c(3,5))
  </code></pre>
  
  <p>I want to create a third column in this df based on the start-end</p>
  
  <pre><code>&gt;df
  
  start end
  1     1   3   mean(a[1:3])
  2     4   5   mean(a[4:5])
  </code></pre>
  
  <p>of course mean(a[df$start:df$end]) does not work.
  I have solved this in a long manner by creating a new data.frame, but I am wondering if is there a short way to do.</p>