title: Apply aggregation function to multiple data.table columns with customized output names
body: <p>Apologies if this is a duplicate. I am very new to data.table, and have seen very similar questions asked here but none that exactly answered my question.</p>
  <p>I would like to find a concise syntax to aggregate multiple columns of a data.table with the same aggregation function, with customized names of the resulting aggregated columns.</p>
  <h3>setup</h3>
  <pre><code>library(data.table)
  data(mtcars)
  setDT(mtcars)
  </code></pre>
  <p>If I call</p>
  <pre><code>mtcars[, lapply(.SD, sum, na.rm = TRUE), by = .(am, gear), .SDcols = c('mpg','cyl')]
  </code></pre>
  <p>The result is</p>
  <pre><code>   am gear   mpg cyl
  1:  1    4 210.2  36
  2:  0    3 241.6 112
  3:  0    4  84.2  20
  4:  1    5 106.9  30
  </code></pre>
  <p>This is great but I want the last two columns to be called by customized names that I define ahead of time.</p>
  <p>I can achieve the desired result with</p>
  <pre><code>mtcars[, .(sum_of_mpg = sum(mpg, na.rm = TRUE), sum_of_cyl = sum(cyl, na.rm = TRUE)), by = .(am, gear)]
  </code></pre>
  <p>This results in</p>
  <pre><code>  am gear sum_of_mpg sum_of_cyl
  1:  1    4      210.2         36
  2:  0    3      241.6        112
  3:  0    4       84.2         20
  4:  1    5      106.9         30
  </code></pre>
  <p>But this result cannot be generalized to allow me to define the custom names beforehand.</p>
  <p>I've tried the code below and various variants of it, but nothing gives this result in one step.</p>
  <pre><code>custom_names &lt;- c('sum_of_mpg','sum_of_cyl')
  mtcars[, (custom_names) = lapply(.SD, sum, na.rm = TRUE), by = .(am, gear), .SDcols = c('mpg','cyl')]
  </code></pre>
  <p>Is there a way to do this concisely? This is necessary because the code may be embedded in a function and may need to work on an indefinite number of columns.</p>