3

I've been playing around with data.tables and noticed some strange behaviour & not sure if I'm doing something wrong or not.

If I reassign a data.table to another name then drop a column from the new table it also drops it from the first table. Eg:

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

Yet if I use the data.frame approach it doesn't impact a. Eg:

> b$z <- NULL
> dim(a)
[1] 10  3
> dim(b)
[1] 10  2

Am I doing something wrong with data.tables or is it just a quirk?

Yass
  • 43
  • 6

0 Answers0