Mutating multiple columns in a data frame using dplyr
<p>I have the following data frame <code>df</code>:</p>

<pre><code>  v1 v2 v3 v4
1  1  5  7  4
2  2  6 10  3
</code></pre>

<p>And I want to obtain the following data frame <code>df2</code> multiplying columns v1*v3 and v2*v4:</p>

<pre><code>  v1 v2 v3 v4 v1v3 v2v4
1  1  5  7  4    7   20
2  2  6 10  3   20   18
</code></pre>

<p>How can I do that using <code>dplyr</code>? Using <code>mutate_each</code>?</p>

<p>I need a solution that can be <strong>generalized to a large number of variables</strong> and not only 4 (v1 to v4).
This is the code to generate the example:</p>

<pre><code>v1 &lt;- c(1, 2)
v2 &lt;- c(5,6)
v3 &lt;- c(7, 10)
v4 &lt;- c(4, 3)
df &lt;- data.frame(v1, v2, v3, v4)
v1v3 &lt;- c(v1 * v3)
v2v4 &lt;- c(v2 * v4)
df2 &lt;- cbind(df, v1v3, v2v4)
</code></pre>