title: sum variables within R dataframe
body: <p>I'm sorry, I'm sure a similar question has already been asked but I'm afraid I can't find it.  I merely want to sum a lot of variables within a dataframe.  As a small example, what I'd like to do is calculate df$e as below.</p>
  
  <pre><code>df &lt;- data.frame(a=c(1,2,3,4,5), b=(c(6,7,8,9,10)), 
                   c=c(1,2,3,4,5), d=(c(6,7,8,9,10)))
  
  df$e &lt;- with(df, a+b+c+d) # this is the right answer
  </code></pre>
  
  <p>But I want to express it by saying df$e &lt;- "the sum of all the variables between a and d."</p>
  
  <p>Thank you!  Help also appreciated in tagging.</p>
  
  <p>ANSWER: <code>df$e &lt;- rowSums(subset(df, select=a:d))</code></p>
  
  <p>I didn't express that I needed it very clearly, but I was as ignorant of <code>subset</code> as I was of <code>rowSums</code>.</p>