title: R: apply a function to every element of two variables respectively
body: <p>I have a function with two variables x and y:</p>
  
  <pre><code>fun1 &lt;- function(x,y) {
    z &lt;- x+y
    return(z)
  }
  </code></pre>
  
  <p>The function work fine by itself:</p>
  
  <pre><code>fun1(15,20)
  </code></pre>
  
  <p>But when I try to use it with two vectors for x and y with an apply function I do not get the correct 56*121 array</p>
  
  <pre><code>Lx  &lt;- c(1:56)
  Ly &lt;- c(1:121)
  
  mapply(fun1, Lx, Ly)
  </code></pre>
  
  <p>I would be grateful for your help and also on advice on the fastest solution (eg is a data.table or dplyr solution faster than apply). </p>