title: create a new column in a data.table from group by multiple columns
body: <p>I'm working on a data.table that includes X and Y columns and I want to create a new column Z which is the number of all records with the same value of (X, Y).   </p>
  
  <p>I know the syntax when working with a data.frame:</p>
  
  <pre><code>ddply(df,.(X,Y),nrow)
  </code></pre>
  
  <p>I tested different syntaxes I found on this forum but they didn't work:   </p>
  
  <pre><code>dt[, Z := lapply(.SD,nrow), by="X,Y"] # or   
  dt[, `:=`(Z = lapply(.SD,nrow)), by="X,Y"]   
  </code></pre>
  
  <p>I precise X and Y are numeric.</p>