title: R data.table "by" for "i"
body: <p>In a given data.table what would be the syntax to select column V1 where V2 = max(V2), grouped by V3.</p>
  
  <p>For example:
  In the mtcars dataset, I would like to find out what is the <strong>hp</strong> that corresponds to the observation equal to <strong>max(disp)</strong>, grouped by <strong>cyl</strong></p>
  
  <p>Here is my ungraceful solution, using <em>which</em>:</p>
  
  <pre><code>mtcars &lt;- data.table(mtcars)
  mtcars[which(mtcars$disp %in% mtcars[, max(disp), by = .(cyl)]$V1), .(cyl,hp)]
     cyl  hp
  1:   6 110
  2:   4  62
  3:   8 205
  </code></pre>
  
  <p>Is there a more "data.table" way of achieving the same result?</p>