title: dplyr: Difference between unique and distinct
body: <p>Seems the number of resulting rows is different when using distinct vs unique. The data set I am working with is huge. Hope the code is OK to understand.</p>
  
  <pre><code>dt2a &lt;- select(dt, mutation.genome.position, 
    mutation.cds, primary.site, sample.name, mutation.id) %&gt;%
    group_by(mutation.genome.position, mutation.cds, primary.site) %&gt;% 
    mutate(occ = nrow(.)) %&gt;%
    select(-sample.name) %&gt;% distinct()
  dim(dt2a)
  [1] 2316382       5
  
  ## Using unique instead
  dt2b &lt;- select(dt, mutation.genome.position, mutation.cds, 
     primary.site, sample.name, mutation.id) %&gt;%
    group_by(mutation.genome.position, mutation.cds, primary.site) %&gt;%
    mutate(occ = nrow(.)) %&gt;%
    select(-sample.name) %&gt;% unique()
  dim(dt2b)
  [1] 2837982       5
  </code></pre>
  
  <p>This is the file I am working with:</p>
  
  <p>sftp://sftp-cancer.sanger.ac.uk/files/grch38/cosmic/v72/CosmicMutantExport.tsv.gz</p>
  
  <pre><code>     dt = fread(fl)
  </code></pre>