title: data.table sum by group and return row with max value
body: <p>I have a data.table in this fashion:    </p>
  
  <pre><code>dd &lt;- data.table(f = c("a", "a", "a", "b", "b"), g = c(1,2,3,4,5))
  dd
  </code></pre>
  
  <p>I need to sum the values <code>g</code> by factor <code>f</code>, and finally return a single row data.table object that has the maximum value of <code>g</code>, but that also contains the factor information. i.e.</p>
  
  <pre><code>___f|g   
  1: b 9
  </code></pre>
  
  <p>My closest attempt so far is</p>
  
  <pre><code>tmp3 &lt;- dd[, sum(g), by = f][, max(V1)]
  tmp3
  </code></pre>
  
  <p>Which results in:</p>
  
  <pre><code>&gt; tmp3
  [1] 9
  </code></pre>
  
  <p>EDIT: I'm ideally looking for a purely data.table piece of code/workflow. I'm surprised that with all the speedy fast split-apply-combine wizardry and ability to subset your data in the form of 'example[i= subset, ]` that I haven't found a straight forward way to subset on a single value condition.</p>