title: How to pass column variables to apply function?
body: <p>I have this <code>data.frame</code>:</p>
  
  <pre><code>  id  |  amount1  | amount2  |  day1  |  day2
   ---------------------------------------------
    A   |    10     |    32    |   0    |   34
    B   |    54     |    44    |   8    |   43
    C   |    45     |    66    |   16   |   99    
  
  df &lt;- data.frame(id=c('A','B','C'), amount1=c(10,54,45), amount2=c(32,44,66),  day1=c(0,8,16), day2=c(34,43,99))
  </code></pre>
  
  <p>on which I would like to <code>apply</code> a function</p>
  
  <pre><code>df$res &lt;-  apply(df, 1, myfunc)
  </code></pre>
  
  <p>where </p>
  
  <pre><code>myfunc &lt;- function(x,y) sum(x) * mean(y)
  </code></pre>
  
  <p>only I'd like to pass the column variables as argument to the function, so that it basically should read</p>
  
  <pre><code> apply(df, 1, myfunc, c(amount1, amount2), c(day1, day2))
  </code></pre>
  
  <p>for the first row this is</p>
  
  <pre><code>myfunc(c(10,32),c(0,34))
  # [1] 714
  </code></pre>
  
  <p>Can this be done?</p>