data.table
在我对 a 进行子集化并将返回值分配给另一个之后,我试图通过引用分配一列data.table
(玩具示例):
> x <- data.table(a=1:10, b=11:20, c=21:30)
> x
a b c
1: 1 11 21
2: 2 12 22
3: 3 13 23
4: 4 14 24
5: 5 15 25
6: 6 16 26
7: 7 17 27
8: 8 18 28
9: 9 19 29
10: 10 20 30
> y <- x[a==1 | a == 2, list(a,b,c)]
> y[,d:=a+b]
Error in `[.data.table`(y, , `:=`(d, a + b)) :
It appears that at some earlier point, names of this data.table have been reassigned. Please ensure to use setnames() rather than names<- or colnames<-. Otherwise, please report to datatable-help.
我不完全理解这个问题:返回y
的只是一个“视图”到相同的内存中x
,因此copy
x
在通过引用设置列之前应该这样做吗?
谢谢