-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
With
library(data.table)
DT = data.table(a = 1, b = 2)
DT[, c(sq = lapply(.SD, "^", 2))]
# sq.a sq.b
# 1: 1 4
DT[, c(sq = lapply(.SD, "^", 2)), by=1]
# NA a b
# 1: 1 1 4
The prefix "sq" disappears in the latter case. Judging by the verbose=TRUE output, this is due to "lapply optimization" which takes names strictly from .SD.
(Sorry if I filed this issue already before this; I'm sure it's bothered me for a while. A recent case: I wanted to write IDDT = dat[order(-t), c(max = .SD[1]), by=ID], but no dice.)
Related: #1604
Reactions are currently unavailable