title: Iterate function across columns in data.frame
body: <p>I want to apply some function from a package in R to every column in one data.frame. As for this function, the data must be structured like the following data.frame called x:</p>
  
  <pre><code>          var1   group
  
  sample1   100     1
  sample2   200     1
  sample3   300     1
  sample4   150     2
  sample5   200     2
  sample6   100     2
  </code></pre>
  
  <p>Using the function on just one column, I must write:</p>
  
  <pre><code>foo &lt;- random.function(x$var1, x$group)
  </code></pre>
  
  <p>But what I have is a data.frame with many variables (var1,var2,var3,var4...) and want to apply this function to each column independently.</p>
  
  <p>I have tried the following:</p>
  
  <pre><code>foo2 &lt;- apply(x, 2, function(x) random.function(x, group))
  </code></pre>
  
  <p>But I get an error saying that variables are not numeric.</p>
  
  <p>I think the problem deals with asigning a name to the x and group inside the random.function call for apply.</p>
  
  <p>Do you know how could I solve this issue?</p>
  
  <p>Thanks</p>