title: Sort and then select the first row by group with data.table?
body: <p>How do I first sort and then select the first row by group with data.table?</p>
  
  <p>Originally the procedure was implement using dplry </p>
  
  <pre><code>dat_dplyr &lt;- dat %&gt;% group_by(V1, V2) %&gt;% arrange(V1, V2, desc(V3), desc(V4)) %&gt;% filter(row_number() == 1)
  </code></pre>
  
  <p>This works, but a bit slow. So what would be the data.table equivalent? Would it be</p>
  
  <pre><code>DT &lt;- as.data.table(dat)
  test &lt;- DT[order(-V3,-V4), .SD[1], by = .(V1, V2)]
  </code></pre>
  
  <p>Thanks very much for your help!</p>