title: R dplyr to data table - Group and Filter
body: <p>I am trying to transform my data manipulation code from <code>dplyr</code> to <code>data.table</code> for speed reasons. I am almost there but missing the final step. </p>
  
  <p>I have some sample data to replicate my problem. </p>
  
  <pre><code>c_dt = data.table(u_id=rep(c("u1", "u2"),each=5),
                    p_id=c("p1", "p1", "p1", "p2","p2", "p1", "p2", "p2", "p2", "p2" ), 
                    c_dt=c("2015-12-01", "2015-12-02", "2015-12-03", "2015-12-02",
                           "2015-12-05", "2015-12-02", "2015-12-03", "2015-12-04", 
                           "2015-12-05", "2015-12-06"))
  </code></pre>
  
  <p>I wish to identify the rows where <code>u_id</code> and <code>p_id</code> is duplicated; and keep only the row with the minimum <code>c_dt</code> (essentially keep the first instance). I use the following <code>dplyr</code> code for this:</p>
  
  <pre><code>c_df &lt;- as.data.frame(c_dt)
  cdedup_df &lt;- c_df %&gt;% group_by(p_id, u_id) %&gt;% filter(c_dt == min(c_dt))
  </code></pre>
  
  <p>Which give the below output </p>
  
  <pre><code>&gt; cdedup_df
  Source: local data frame [4 x 3]
  Groups: p_id, u_id
  
    u_id p_id       c_dt
  1   u1   p1 2015-12-01
  2   u1   p2 2015-12-02
  3   u2   p1 2015-12-02
  4   u2   p2 2015-12-03
  </code></pre>
  
  <p>I have the following <code>data.table</code> code that correctly identifies the required rows but I am unable to figure out how to just filter and the row as it is. </p>
  
  <pre><code>cdedup_dt &lt;- c_dt[,c_dt == min(c_dt),by = list(u_id, p_id)]
  cdedup_dt
      u_id p_id    V1
   1:   u1   p1  TRUE
   2:   u1   p1 FALSE
   3:   u1   p1 FALSE
   4:   u1   p2  TRUE
   5:   u1   p2 FALSE
   6:   u2   p1  TRUE
   7:   u2   p2  TRUE
   8:   u2   p2 FALSE
   9:   u2   p2 FALSE
  10:   u2   p2 FALSE
  </code></pre>