title: Return multiple values from apply() function in R
body: <p>I am wanting to return multiple values from the apply() function and place them in separate columns in R but I keep getting errors. What I am trying to do is this:</p>
  
  <pre><code>experiments$result1, experiments$result2, experiments$result3 &lt;- apply(experiments, 1, 
  function(row)
    #Some analysis here
    #return x, y, and z for column result1, result2, and result3
    x, y, z
  )
  </code></pre>
  
  <p>Maybe this is the wrong approach to the problem. Experiments is a data frame with several columns of data. I am wanting to append columns which are the result of the analysis for each row but I don't know how to do that without loops which is not idiomatic for R. Thanks for the help ahead of time.</p>
  
  <p>So here is some more exact code.</p>
  
  <pre><code>experiments$result1, experiments$result2, experiments$result3 &lt;- apply(experiments, 1, function(row)
    x &lt;- row["startingTemp"]*2
    y &lt;- row["startingTemp"]*3
    z &lt;- row["startingTemp"]*4
    return (list(x, y, z))
  )
  </code></pre>
  
  <p>the "startingTemp" field is one of the columns in my "experiments" data frame. I'm getting errors that the type 'closure' is not subsettable and object 'z' not found.</p>