title: How to perform operation between grouped values from two data frames
body: <p>I have two data frames:</p>
  
  <p>
  <br/></p>
  
  <pre class="lang-r prettyprint-override"><code>src_tbl &lt;- structure(list(Sample_name = c("S1", "S2", "S1", "S2", "S1", 
  "S2"), crt = c(0.079, 0.082, 0.079, 0.082, 0.079, 0.082), sr = c(0.592, 
  0.549, 0.592, 0.549, 0.592, 0.549), condition = c("x1", "x1", 
  "x2", "x2", "x3", "x3"), score = c("0.077", "0.075", "0.483", 
  "0.268", "0.555", "0.120")), row.names = c(NA, -6L), .Names = c("Sample_name", 
  "crt", "sr", "condition", "score"), class = c("tbl_df", 
  "tbl", "data.frame"))
  src_tbl
  #&gt;   Sample_name   crt    sr condition score
  #&gt; 1          S1 0.079 0.592        x1 0.077
  #&gt; 2          S2 0.082 0.549        x1 0.075
  #&gt; 3          S1 0.079 0.592        x2 0.483
  #&gt; 4          S2 0.082 0.549        x2 0.268
  #&gt; 5          S1 0.079 0.592        x3 0.555
  #&gt; 6          S2 0.082 0.549        x3 0.120
  
  ref_tbl &lt;- structure(list(Sample_name = c("P1", "P2", "P3", "P1", "P2", 
  "P3", "P1", "P2", "P3"), crt = c(1, 1, 1, 1, 1, 1, 1, 1, 1), 
      sr = c(2, 2, 2, 2, 2, 2, 2, 2, 2), condition = c("r1", "r1", 
      "r1", "r2", "r2", "r2", "r3", "r3", "r3"), score = c("0.200", 
      "0.201", "0.199", "0.200", "0.202", "0.200", "0.200", "0.204", 
      "0.197")), row.names = c(NA, -9L), .Names = c("Sample_name", 
  "crt", "sr", "condition", "score"), class = c("tbl_df", 
  "tbl", "data.frame"))
  ref_tbl
  #&gt;   Sample_name crt sr condition score
  #&gt; 1          P1   1  2        r1 0.200
  #&gt; 2          P2   1  2        r1 0.201
  #&gt; 3          P3   1  2        r1 0.199
  #&gt; 4          P1   1  2        r2 0.200
  #&gt; 5          P2   1  2        r2 0.202
  #&gt; 6          P3   1  2        r2 0.200
  #&gt; 7          P1   1  2        r3 0.200
  #&gt; 8          P2   1  2        r3 0.204
  #&gt; 9          P3   1  2        r3 0.197
  </code></pre>
  
  <p>What I want to do is to perform operation (<code>ks.test()</code>) on <code>score</code> columns grouped by <code>Sample_name</code> in both data frame. For example the p-value of KS test for S1 and P1 is:</p>
  
  <p>
  <br/></p>
  
  <pre class="lang-r prettyprint-override"><code># in src_tbl
  s1 &lt;- c(0.077,0.483,0.555)
  #in ref_tbl
  p1 &lt;- c(0.200,0.200,0.200)
  testout &lt;- ks.test(s1,p1)
  #&gt; Warning in ks.test(s1, p1): cannot compute exact p-value with ties
  broom::tidy(testout)
  #&gt;   statistic   p.value                             method alternative
  #&gt; 1 0.6666667 0.5175508 Two-sample Kolmogorov-Smirnov test   two-sided
  </code></pre>
  
  <p>What I want to do is to perform all against all operation so that in the end, we get table like this</p>
  
  <pre class="lang-r prettyprint-override"><code>src  ref   p.value
  S1   P1    0.5175508
  S1   P2    0.6
  S1   P3    0.6
  S2   P1    0.5175508
  S2   P2    0.6
  S2   P3    0.6
  </code></pre>
  
  <p>How can I do that? Preferrable to be fast because the number of samples in <code>ref_table</code> could be large (P1, P2 .... P10k).</p>