title: How to group by similar element in the lists
body: <p>In my program I want to perform a <strong>groupBy</strong> operation on the dataframe using the common element in the list. For example the following dataframe:  </p>
  
  <pre><code>visitorId   |trackingIds     |emailIds
  +-----------+----------------+--------
  [a158]      |[666b,666b,777c]|[12]
  [7g21]      |[c0b5,c0b4]     |[45, 87]
  [p9098]     |[666b]          |[90]
  [8u7t]      |[c0b5]          |[40]
  </code></pre>
  
  <p>Should be grouped by the column <strong>trackingIds</strong>, which is actually a List[String]</p>
  
  <pre><code>visitorId          |trackingIds     |emailIds
  +------------------+----------------+------------
  [a158, p9098]      |[666b,666b,777c]|[12, 90]
  [7g21, 8u7t]       |[c0b5,c0b4]     |[45, 87, 40]
  </code></pre>
  
  <p>I have a solution using a simple function that finds the element in other rows and merges accordingly but looking for a solution that would be cost effective, as the operation is to be performed on a big dataframe with millions of rows.</p>