title: Apply over two data frames
body: <p>I'm using R, and I have two data.frames, <code>A</code> and <code>B</code>. They both have 6 rows, but <code>A</code> has 25000 columns (genes), and <code>B</code> has 30 columns. I'd like to apply a function with two arguments <code>f(x,y)</code> where <code>x</code> is every column of <code>A</code> and <code>y</code> is every column of <code>B</code>. So far it looks like this:</p>
  
  <pre><code>i = 1
  for (x in A){
      j = 1
      for (y in B){
          out[i,j] &lt;- f(x,y)
          j = j + 1
      }
      i = i + 1
  }
  </code></pre>
  
  <p>I have two issues with this: from my Python programming I associate keeping track of counters like this as crufty, and from my R programming I am nervous of for loops. However, I can't quite see how to apply <code>apply</code> (or even if I should apply <code>apply</code>) to this problem and was hoping someone might enlighten me. I need to treat <code>f()</code> as atomic (it's actually <code>cor.test()</code>) for now.</p>