title: Output function results to a vector
body: <p>I have created a function to call a function on each row in a dataset. I would like to have the output as a vector. As you can see below the function outputs the results to the screen, but I cannot figure out how to redirect the output to a vector that I can use outside the function. </p>
  
  <pre><code>n_markers &lt;- nrow(data)
  p_values &lt;-rep(0, n_markers)
  
  test_markers &lt;- function()
     {
     for (i in 1:n_markers)
        {
        hets  &lt;- data[i, 2]
        hom_1 &lt;- data[i, 3]
        hom_2 &lt;- data[i, 4]   
        p_values[i] &lt;- SNPHWE(hets, hom_1, hom_2)
        }
        return(p_values)
     }
  
  test_markers()
  </code></pre>