title: apply() optimize() on a data frame or matrix?
body: <p>I have a dataframe, and a cost function that I want to optimize given each row in the data frame.</p>
  
  <p>simplified example:</p>
  
  <pre><code>funct &lt;- function(x,row,y)
  {
    r &lt;- row**2 - (x*y)**3
    return(sum(r))
  
  }
  apply(dataFr,1,optimize,f=funct,interval=c(0,250),y=4)
  </code></pre>
  
  <p>funct is the cost function, x is the variable I want to optimize over, and row is an argument that represents a row in a data frame dataFr</p>
  
  <p>When I run the above code I get an error</p>
  
  <pre><code>Error in f(arg, ...) : unused argument (c(4, 8, 23))
  </code></pre>
  
  <p>What I want to get is a list of x's that optimze the cost, given each row in dataFr</p>
  
  <p>dataFr can be </p>
  
  <pre><code>  X1 X2 X3
  1  4  8 23
  2  2  4 12
  3  3  5 65
  </code></pre>