title: Identify which pairs of rows are most similar (string distance) in a data.frame
body: <p>Let's say I have the following data.frame</p>
  <pre><code>test_df = read.table(text = &quot;id, chat
  11, hey how are you im doing well
  12, hey how are you im
  13, my name is bob
  14, my name is bob. how are you?
  15, test test
  16, test testing
  17, who is this
  18, who is this. who are you?&quot;, header = T, sep = &quot;,&quot;)
  </code></pre>
  <p>I'm trying to identify which pairs of rows, for the column <code>chat</code> have the most similar values via string distance. I then want to create a column <code>partner_id</code> which identifies the id of the person with the most similar value of <code>chat</code>.</p>
  <p>Here's the desired output:</p>
  <pre><code>final_df = read.table(text = &quot;id, chat, partner_id
  11, hey how are you im doing well, 12
  12, hey how are you im, 11
  13, my name is bob, 14
  14, my name is bob. how are you?, 13
  15, test test, 16
  16, test testing, 15
  17, who is this, 18
  18, who is this. who are you?, 17&quot;, header = T, sep = &quot;,&quot;)
  </code></pre>
  <p>I know that the <code>stringdist</code> library has various fuzzy matching calculations, but I can't think of a better solution than just iterating over all the rows, computing every pairwise string distance, and then storing the best solution (which becomes computationally challenging with big data.frames). It's particularly challenging since every id can only have exactly one partner_id, so once a &quot;best&quot; match has been selected, that <code>id</code> should no longer be available for matching.</p>