title: In R, apply a function to the rows of a data frame and return a data frame
body: <p>I am trying to apply a self-written function to the rows of a data frame.</p>
  
  <pre><code>library(dplyr) # only used for data_frame
  DF = data_frame(x = c(50, 49, 20), y = c(132, 124, 130), z = c(0.82, 1, 0.63))
  
       x     y     z
     &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
  1    50   132  0.82
  2    49   124  1.00
  3    20   130  0.63
  </code></pre>
  
  <p>The actual data frame has thousands of rows, this is just a sample.</p>
  
  <p>My function is very complicated and does many things, and in the end I get for each row of DF a new row.
  Let's say for simplicity that the function adds 1 to column 1, 2 to column 2 and 3 to column 3 (this of course can be vectorized, but my function, lets call it Funct, does much more).
  So:</p>
  
  <pre><code>Funct = function(DF) {
     DF[1]= DF[1]+1
     DF[2] = DF[2]+2
     DF[3] = DF[3]+3
     return(DF)
  }
  </code></pre>
  
  <p>How do I apply this function in the most efficient way to get in the end a new data frame with the output:</p>
  
  <pre><code>&gt; DF
       x     y     z
     &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
  1    51   134  3.82
  2    50   126  4.00
  3    21   132  3.63
  </code></pre>