title: Getting one row per group in R data.table
body: <p>I often want to process one row of a data.table at a time.  I've been using </p>
  
  <pre><code>d[, j, by=rownames(d)]
  </code></pre>
  
  <p>but this doesn't always seem to work (sometimes getting an error message about by appearing to evaluate to column names), and in any case isn't a very clean expression of what I'm trying to do. </p>
  
  <p>Let me give a specific example.</p>
  
  <pre><code>d = data.table(a=c(1,2),b=c(3,4))
  f = function(x,y) x[1]+y[1] #expects length 1 vectors x and y and adds them
  d[, id := 1:.N]
  d[, f(a,b), by=id]
  d[, id := NULL]
  </code></pre>
  
  <p>The situation is that I have a function f that is not vectorized.  I've decorated d with an id column so I can process one row at a time. I'm looking for a better way to do this.</p>
  
  <p>Here's another example, without a function f:</p>
  
  <pre><code>d[, list(a=a,b=b,s=a:b), by = id]
  d[, id := NULL]
  </code></pre>