1

This might be a very silly question. But let's say I have data.table called x <- data.table(c(1:5),c(2:6))

Then I assign another variable to it: y <- x. How come when I do something to y using the := operator it changes the original x data.table?

> x <- data.table(c(1:5),c(2:6))
> y <- x
> y <- y[,testing := V1 + V2]
> y
   V1 V2 testing
1:  1  2       3
2:  2  3       5
3:  3  4       7
4:  4  5       9
5:  5  6      11
> x
   V1 V2 testing
1:  1  2       3
2:  2  3       5
3:  3  4       7
4:  4  5       9
5:  5  6      11

Is there any way to use the data.table := operator without this occurring?

road_to_quantdom
  • 1,341
  • 1
  • 13
  • 20

0 Answers0