Can I create a new column in a data table and update an existing column at the same time? The following did not work. Thanks.
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]
Caught Segfault:
address 0x20000010, cause 'memory not mapped'
Traceback:
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]
source share