title: Renaming multiple columns in R data.table
body: <p>This is related to this question from Henrik
  <a href="https://stackoverflow.com/questions/11680579/assign-multiple-columns-using-in-data-table-by-group#">Assign multiple columns using := in data.table, by group</a></p>
  
  <p>But what if I want to <strong>create</strong> a new data.table with given column names instead of <strong>assigning</strong> new columns to an existing one?</p>
  
  <pre><code>f &lt;- function(x){list(head(x,2),tail(x,2))}
  dt &lt;- data.table(group=sample(c('a','b'),10,replace = TRUE),val=1:10)
  </code></pre>
  
  <hr>
  
  <pre><code>&gt; dt
      group val
   1:     b   1
   2:     b   2
   3:     a   3
   4:     b   4
   5:     a   5
   6:     b   6
   7:     a   7
   8:     a   8
   9:     b   9
  10:     b  10
  </code></pre>
  
  <p>I want to get a new data.table with predefined column names by calling the function <code>f</code>:</p>
  
  <pre><code>dt[,c('head','tail')=f(val),by=group]
  </code></pre>
  
  <p>I <strong>wish</strong> to get this:</p>
  
  <pre><code>   group head tail
  1:     a    1    8
  2:     a    3   10
  3:     b    2    6
  4:     b    5    9
  </code></pre>
  
  <p>But it gives me an error. What I can do is create the table then change the column names, but that seems cumbersome:</p>
  
  <pre><code>&gt; dt2 &lt;- dt[,f(val),by=group]
  
  &gt; dt2
     group V1 V2
  1:     a  1  8
  2:     a  3 10
  3:     b  2  6
  4:     b  5  9
  
  &gt; colnames(dt2)[-1] &lt;- c('head','tail')
  
  &gt; dt2
     group head tail
  1:     a    1    8
  2:     a    3   10
  3:     b    2    6
  4:     b    5    9
  </code></pre>
  
  <p>Is it something I can do with one call?</p>