title: Howto calculate distance between two groups of data
body: <p>I've got 2 data frames - learn data with L rows and test data with T rows.</p>
  
  <p>I want to compute a L*T matrix with distances (euclidean, manhattan, cosine...) between according elements.</p>
  
  <p>Here is my take:</p>
  
  <pre><code>distance2 &lt;- function (x1, x2) {
              temp &lt;- x1 - x2
              sum(temp * temp)
  }
  
  m &lt;- matrix(0,nrow(learnData),nrow(testData))
  for(td in 1:nrow(testData)) {
      for(ld in 1:nrow(learnData)) {
          m[ld,td] &lt;- distance2(testData[td,],learnData[ld,])                 
      }
  }
  </code></pre>
  
  <p>I think this can be done in a more compact, "R" way. Any ideas?
  Thanks.</p>