title: how to find common variable pairs in R?
body: <p>I have a data frame with 2 columns, ID and a category name:</p>
  
  <pre><code>     X1     X2
      1234   Metal
      1234   Metal
      1234   Plastic
      1234   Plastic
      1234   Glass
      1235   Metal
      1235   Metal
      1235   Plastic
      1235   Plastic
      1235   Glass
      1236   Glass
      1236   Glass
      1236   Metal
      1236   Metal
      1236   Plastic
  </code></pre>
  
  <p>I want to find the most frequent combinations and the count of those combinations of 2 (I will want combinations of 3 or 4 for a larger dataset) across the entire dataset:</p>
  
  <pre><code>    Metal, Plastic     2
      Glass, Metal       1
  </code></pre>
  
  <p>I tried to first generate all possible combinations of <code>X2</code> by ID (<code>X1</code>), so I could then use <code>dplyr</code> to aggregate and subset the top combinations. Unfortunately, my dataset is too large for this to run efficiently. Any ideas on an easier and faster way to figure this out?</p>