是否可以在 data.table 中创建新列并同时更新现有列?以下没有奏效。谢谢。
library(data.table)
dt <- data.table(x=runif(4), y=runif(4), z=c("x","x","y","y"))
dt[, c("x", "y") := list(x[1], y[1]), by=z] # works
dt[, c("x", "newx") := list(x[1], y[1]), by=z]
捕获段错误:
address 0x20000010, cause 'memory not mapped'
追溯:
1: [.data.table(dt, , :=(c("x", "newx"), list(x[1], y[1])), by = z)
2: dt[, :=(c("x", "newx"), list(x[1], y[1])), by = z]