title: Apply function to convert dataframe rows to vectors
body: <p>I have a dataframe with 12665x784 dimension and I need to call a function over each row (this function expects an input of 1x784 from the dataframe and a constant with the same size) and store the result in another vector. The code using for loop is shown bellow:</p>
  
  <pre><code>sample &lt;- 1:20
  my.constant &lt;- 1:5
  dim(sample) &lt;- c(4, 5)
  df &lt;- as.data.frame(sample)
  
  my.function &lt;- function (x, y){
    y &lt;- as.matrix(y)
    x &lt;- as.matrix(x)
    return(x%*%y)
  }
  
  result &lt;- c()
  
  for (row in 1:nrow(df)) {
    result&lt;- c(result, my.function(df[row, ], my.constant))
  }
  </code></pre>
  
  <p>I've tried the following approach, but it didn't work:</p>
  
  <pre><code>result &lt;- sapply(lapply(df, as.vector), my.function, my.constant)
  </code></pre>