Column range sums with dplyr's `mutate`
<p>I want to sum up several rows in a data frame using <code>mutate</code>.</p>

<pre><code># Create the data - one row per order
f &lt;- data.frame(
  customer = rep(c(1,2), each = 4), 
  order_type = rep(c("direct","express","air","regular"), 2), 
  count = sample(1:100, 8, replace = T))

# Spread the order data per-customer 
f &lt;- f %&gt;%
  spread(order_type, count, fill = 0) 

# Try to use mutate to sum up all types of orders
f %&gt;%
  mutate(total = select(., air:regular) %&gt;% rowSums)
</code></pre>

<p>I am expecting that the last call to mutate will populate a new column with the sum of the rows from <code>air</code> to <code>regular</code>. If I call <code>select(f, air:regular) %&gt;% rowSums</code> outside of <code>mutate</code>, I get a vector with the sums. However, within <code>mutate</code>, I get the following error:</p>

<pre><code>Error: Position must be between 0 and n
In addition: Warning messages:
1: In c(10, 14):c(96, 83) :
  numerical expression has 2 elements: only the first used
2: In c(10, 14):c(96, 83) :
  numerical expression has 2 elements: only the first used
</code></pre>

<p>I believe I am missing some fundamental point about <code>mutate</code> and its evaluation scheme.</p>

<p>I would like to understand how to perform this transformation with <code>dplyr</code>. </p>

<p>Thanks!</p>