title: Normalize a variable data.table
body: <p>I'm looking to normalize a variable in a data.table by subtracting the mean within each group. I have done it in the following manner:</p>
  
  <pre><code>dx &lt;- data.table(x=c(1,3,5,1,8,11),group=factor(c(1,1,1,2,2,2)))
  dy &lt;- dx[,.(xmean=mean(x)),by=.(group)]
  setkey(dx,group)
  setkey(dy,group)
  dx[dy,x_norm:=x-xmean]
  </code></pre>
  
  <p>I'm wondering if there is a more concise way of doing this?</p>