title: Skip NA in data.table by
body: <p>I'd like to use <code>data.table</code> but would like skip the calculation of the <code>j</code> part if the <code>by</code> corresponds to missing (<code>NA</code>):</p>
  
  <p>Here is an example data.table</p>
  
  <pre><code>library(data.table)
  DT &lt;- data.table(y=10, g=c(1,1,1,2,2,2,2,2,NA,NA))
  </code></pre>
  
  <p>It looks like this</p>
  
  <pre><code>&gt; DT
       y  g
   1: 10  1
   2: 10  1
   3: 10  1
   4: 10  2
   5: 10  2
   6: 10  2
   7: 10  2
   8: 10  2
   9: 10 NA
  10: 10 NA
  </code></pre>
  
  <p>Now I'd like to do the <code>by=</code> on <code>g</code> and the two rows 9 and 10 will be lumped together because they have the same value <code>NA</code>.</p>
  
  <pre><code>&gt; DT[,.N, by=g]
      g N
  1:  1 3
  2:  2 5
  3: NA 2
  </code></pre>
  
  <p>I'd like to keep the <code>NA</code> line in the output but would want to skip the calculate part in the result, ie., get the output, where <code>N</code> is empty when <code>g</code> is <code>NA</code></p>
  
  <pre><code>&gt; DT[,.N, by=g]
      g N
  1:  1 3
  2:  2 5
  3: NA NA
  </code></pre>
  
  <p>I thought I could access the value of <code>g</code> through <code>.GRP</code> but that only gives the group index and not the value. Is it possible to make the calculation conditional on the missing status of the <code>by</code> variable? </p>