title: retaining column names in lapply(.SD,...) for data.table R
body: <p>When applying a function with multiple output variables (e.g., a list) to a subset of a data.table, I lose the variable names. Is there a way to retain them? </p>
  
  <pre><code>library(data.table)
  
  foo &lt;- function(x){
    list(mn = mean(x), sd = sd(x))
  }
  
  bar &lt;- data.table(x=1:8, y=c("d","e","f","g"))
  
  # column names "mn" and "sd" are replaced by "V1" and "V2"
  bar[, sapply(.SD, foo), by = y, .SDcols="x"]
  
  # column names "mn" and "sd" are retained
  bar_split &lt;- split(bar$x, bar$y)
  t(sapply(bar_split, foo))
  </code></pre>