I'm trying to combine .SD with some other columns in a summarize operation, but this results in incorrect results (for my objective). For (a silly) example:
library(data.table)
t <- as.data.table(mtcars)
t[, list(cyl = sum(cyl), lapply(.SD, mean)), .SDcols = c('mpg', 'disp')]
I'd like this to return a data.table with 1 row and 3 columns, but instead it returns a column with 2 rows and 2 columns. Is there a way around this?