【发布时间】:2014-06-28 09:29:56
【问题描述】:
让我们来:
DT1 <- data.table(iris)
DT2 <- DT1 # both reference the same memory location though
DT3 <- copy(DT1)
问题:有没有办法检查DT2 是否一直引用与DT1 相同的内存位置?
类似这样的伪函数:
mem.identical(DT2, DT1) # should return TRUE
mem.identical(DT3, DT1) # should return FALSE
很遗憾,identical 或 all.equal 不适用于此目的,因为
identical(DT1,DT3) # gives TRUE
只有引入一些变化后,才能使用identical检测差异:
DT1[,Test:=1] # introduces change to DT1 directly, to DT2 indirectly
identical(DT1,DT2) # TRUE - proves that DT2 is linked with DT1
identical(DT1,DT3) # FALSE - DT1 and DT3 are clearly decoupled
【问题讨论】:
-
这是一个不同的问题,有重复的答案:stackoverflow.com/a/10913296/403310(我之所以发现它是因为它在
address的文档中链接) -
@BenBolker 实际上增加的价值是@GSee 的
data.table::address解决方案,我在其他地方没有找到
标签: r data.table