title: Finding most frequent combinations
body: <p>I have a data frame with 2 columns, ID number and brand: </p>
  
  <pre><code>X1     X2
  1234   A89
  1234   A87
  1234   A87
  1234   A32
  1234   A27
  1234   A27
  1235   A12
  1235   A14
  1235   A14
  1236   A32
  1236   A32
  1236   A27
  1236   A12
  1236   A12
  1236   A14
  1236   A89
  1236   A87
  1237   A99
  1237   A98
  </code></pre>
  
  <p>I want to find the top 3 brand combinations that occur together most frequently with regard to id number:</p>
  
  <pre><code>A89, A87
  A32, A27
  A12, A14
  </code></pre>
  
  <p>I tried:
      library(dplyr)</p>
  
  <pre><code> df %&gt;% 
    group_by(X1,X2) %&gt;%
    mutate(n = n()) %&gt;%
    group_by(X1) %&gt;%
    slice(which.max(n)) %&gt;%
    select(-n)
  </code></pre>
  
  <p>But it doesn't work correctly. I would appreciate any thoughts or ideas!</p>