title: Using mapply() For Column Row Comparison
body: <p>I am working with two different large data set and trying to make use of <code>mapply()</code> to get iterative functions working.</p>
  
  <p>The goal is to take each data point column wise from <em>Data_1</em>, and compare it against both the data points in column of <em>Data_2</em>. So, <em>Data_1[1,1]</em> will be compared against <em>Data_2[1,1]</em> and <em>Data_2[2,1]</em> only. To be more clear, <em>data1</em> column in <em>Data_1</em> will only be compared against <em>dataA</em> elements in <em>Data_2</em>, thus no cross column comparison. </p>
  
  <p><strong>Data_1: NxM</strong></p>
  
  <pre><code>  data1       data2       data3      data4
  -0.710003   -0.714271   -0.709946   -0.713645
  -0.710458   -0.715011   -0.710117   -0.714157
  -0.71071    -0.714048   -0.710235   -0.713515
  -0.710255   -0.713991   -0.709722   -0.713972
  </code></pre>
  
  <p><strong>Data_2: PxQ</strong></p>
  
  <pre><code>  dataA       dataB       dataC      dataD
  -0.71097    -0.714059   -0.70928    -0.714059
  -0.710343   -0.714576   -0.709338   -0.713644
  </code></pre>
  
  <p>I had earlier written a <code>for()</code> <code>while()</code> loop based algorithm, but the run time was too much as the original data is . Then, I moved to <code>apply()</code> based logic, but still had loops within function I was calling, so that didn't speed up the code. Based on <a href="https://stackoverflow.com/questions/44894649/optimizing-apply-in-r">my earlier question</a>, I am figuring out better way to do this with <code>mapply()</code>.</p>
  
  <p>The part I am not able to visualize is the column to row comparison and how <code>mapply()</code> will navigate over it recursively. How can I use <code>mapply()</code> or <code>lapply()</code> to get this done efficiently?</p>
  
  <p>Any suggestions will be helpful, thanks.</p>