如何防止data.table从复制的表中删除列

时间:2017-06-09 07:00:05

标签: r data.table

为什么在从data.table的副本中删除列时,data.table会从原始data.table中删除列?这对我来说毫无意义。

采用以下示例:

structure(list(pnum = c(7265873, 7266757, 7266757, 7268524, 7268524, 
7272620, 7272620, 7273253, 7273253, 7283628, 7283628, 7289442, 
7289442, 7289525, 7289525, 7289525, 7301987, 7301987, 7305259, 
7305259, 7307986, 7307986, 7310332, 7310332, 7333490, 7333490, 
7333502, 7333502, 7414991, 7414991), invid = c(24104, 38775, 
38776, 34281, 34282, 20002, 22284, 31921, 31922, 26841, 26843, 
17763, 17764, 38087, 38088, 38089, 34843, 38412, 32514, 33946, 
28587, 28588, 17204, 17205, 28587, 28588, 28587, 28588, 37008, 
37009), dom_st = c(0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 2, 2, 0, 
0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0), prim_st = c(1, 
2, 2, 3, 3, 1, 1, 1, 1, 1, 1, 11, 11, 1, 2, 3, 3, 3, 1, 1, 5, 
5, 3, 3, 5, 5, 5, 5, 3, 3), pat_st = c(1, 2, 2, 2, 2, 2, 2, 1, 
1, 1, 1, 48, 63, 1, 1, 1, 1, 1, 1, 1, 5, 5, 14, 14, 5, 5, 5, 
5, 1, 1), net_st = c(0, 3, 3, 2, 2, 0, 0, 4, 4, 2, 2, 10, 9, 
0, 0, 1, 2, 2, 0, 0, 2, 2, 4, 4, 2, 2, 2, 2, 0, 0)), .Names = c("pnum", 
"invid", "dom_st", "prim_st", "pat_st", "net_st"), class = c("data.table", 
"data.frame"), row.names = c(NA, -30L), .internal.selfref = <pointer: 0x0000000000230788>)

假设上面的data.table被称为DT1

现在,如果我执行以下操作:

DT2 <- DT1
DT2[, prim_st:= NULL]

如果我然后检查DT1,那么“prim_st”列也会消失。

为什么呢?以及如何防止这种情况?

0 个答案:

没有答案