title: Sparklyr: get most frequent value for each group
body: <p>I'm looking for a way to group my table by a variable, and get the most frequent observation of another variable (the mode), using <code>sparklyr</code>.</p>
  <p>Here's an example:</p>
  <pre><code>library(sparklyr)
  library(dplyr)
  
  sc &lt;- sparklyr::spark_connect()
  df &lt;- tibble(gp = c('a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'),
              v = c('a1', 'a2', 'a1', 'b1', 'b2', 'b2', 'c1', 'c1', 'c2')) %&gt;%
      sdf_copy_to(sc = sc)
  </code></pre>
  <p>The expected result here would be as below:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>gp</th>
  <th>v</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>a</td>
  <td>a1</td>
  </tr>
  <tr>
  <td>b</td>
  <td>b2</td>
  </tr>
  <tr>
  <td>c</td>
  <td>c1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Since these are the most common values of <code>v</code> for each <code>gp</code></p>
  <p>I saw that in dplyr, you can use <code>names(which.max(table(v)))</code> during the group_by' <code>summarize</code>, but that doesn't work on a sparklyr that I cannot collect.</p>
  <p>Anyone know how I could achieve that result?</p>