Strange behavior dropping column from data.table in R
I have been playing with data.tables and noticed some strange behavior and not sure if I am doing something wrong or not.
If I reassign data.table to a different name and then delete the column from the new table, it will also delete it from the first table. For example:
a <- data.table(x=rnorm(10,3),y=rnorm(10,3),z=rnorm(10,3))
> dim(a)
[1] 10 3
b <- a
b[,z:=NULL]
> dim(a)
[1] 10 2
> dim(b)
[1] 10 2
However, if I use the data.frame approach it has no effect. For example:
> b$z <- NULL
> dim(a)
[1] 10 3
> dim(b)
[1] 10 2
Am I doing something wrong with data.tables or is this just a quirk?
+3
source to share
No one has answered this question yet
See similar questions:
or similar: