是否可以在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]
Run Code Online (Sandbox Code Playgroud)
抓到Segfault:
address 0x20000010, cause 'memory not mapped'
Run Code Online (Sandbox Code Playgroud)
追溯:
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]
Run Code Online (Sandbox Code Playgroud)
是.但是你需要来自R-Forge的v1.8.9来获得以下修复:
o将添加和更新混合到一个DT [,
:=(existingCol = ...,newCol = ...),by = ...]现在无错误或段错误,#2778和#2528.非常感谢Arunkumar Srinivasan的报告和可重复的好例子.测试补充说.
有关v1.8.9中的其他更改,请参阅最新的NEWS(实时更新).