title: data.table group by with a filter condition
body: <p>Given a <code>data.table</code> like the one below, I would like to create a new column which is the <code>value</code> summed by region, and where <code>period == 0</code>. </p>
  
  <pre><code>   region period value
  1:     US      0    10
  2:     US      1    11
  3:  Japan      0    12
  4:  Japan      1    13
  </code></pre>
  
  <p>The typical <code>data.frame</code> approach to this would be to create a separate frame, filter by period, sum by region, and then merge back with the original frame with <code>region</code> as the key. I'm wondering if there is a one-line approach in <code>data.table</code> using the <code>data.table</code> groupby synytax. The closest I've come is the two-line approach below. </p>
  
  <pre><code>x1 &lt;- data.table(
    region=c("US","US","Japan","Japan"),
    period=c(0,1,0,1),
    value=10:13)
  
  x1[period==0,value0:=sum(value),by=region]
  x1[,value0:=min(value0,na.rm=T),by=region]
  
  
     region period value value0
  1:     US      0    10     10
  2:     US      1    11     10
  3:  Japan      0    12     12
  4:  Japan      1    13     12
  </code></pre>