title: Calculate frequency of combination of strings
body: <p>I have a list of number identifiers followed by one or more strings. I would like to calculate for each identifier the longest combination of associated strings that were also present for another identifier. Then also the number of strings associated with each identifier.</p>
  
  <p>E.g.</p>
  
  <pre><code>1   AAA    BBBA    ACA    CCD    ABADA
  2   AAA    ACA     CCD
  3   AAB    BBAC    DDAD
  4   AAA    ACA     DDAD   CCD
  5   AAA    ACA     DDAD   CCD
  </code></pre>
  
  <p>Would result in:</p>
  
  <pre><code>ID  Longest Combo  Number of strings  
  1         3               5
  2         3               3
  3         1               3
  4         4               4
  5         4               4
  </code></pre>
  
  <p>Explanation of results for clarity: </p>
  
  <pre><code>1 - AAA, ACA and CCD present in 2 so longest combo is 3.
  2 - AAA, ACA and CCD present in 1 so longest combo is 3.
  3 - DDAD present in 4 and 5 so longest combo is 1.
  4 - AAA, ACA, DDAD and CCD present in 5 so longest combo is 4.
  5 - AAA, ACA, DDAD and CCD present in 4 so longest combo is 4.
  </code></pre>
  
  <p>Normally I can try and hack something together myself but have hit a wall with this one - not sure where to even begin. The analysis to get to this point takes place in awk so bash would be ideal but potentially this is a job better suited to R?</p>
  
  <p>I was trying to format my data in accordance with this question <a href="https://stackoverflow.com/questions/48562288/frequency-of-each-unique-combination-in-data-frame">Frequency of each unique combination in data frame</a> without success.</p>
  
  <p>Any help would be most appreciated.</p>
  
  <p>There are approximately 3000 identifiers, each with between 1-15 strings.</p>