title: Writing the return of an R loop function into a vector
body: <p>I keep on getting below output: </p>
  
  <pre><code>[1]  0  0  0 22
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>[1]  19  21 21 22
  </code></pre>
  
  <p>for the max number per row in below "data" file:</p>
  
  <pre><code>  A  B  C
  1 1 19 10
  2 2 20 11
  3 3 21 12
  4 4 22 13
  </code></pre>
  
  <p>function used:</p>
  
  <pre><code>f &lt;- function(x) {
       for (i in 1:4) z&lt;- x[i,1:3] 
           count &lt;- max(z)
           y&lt;- vector(length = 4)  
           y[i] &lt;- count
       return(print(y)) 
   }
  </code></pre>
  
  <p>to run the function:</p>
  
  <pre><code> f5 &lt;- f(data)
  </code></pre>
  
  <p>the question is how to let the system write each loop output in the vector and not erase any loop output ! </p>
  
  <p>Thank you in advance, </p>