Consider the following code
library(data.table) # 1.9.2
x <- data.frame(letters[1:2])
setDT(x)
class(x)
## [1] \"data.table\" \"data.frame\"
setDT
changes the data.frame
and returns it invisibly. Since you don't save this data.frame
, it is lost. All you need to do is somehow save the data.frame
, so that the data.table
is also saved. E.g.
setDT(y <- data.frame(x))
class(y)
## [1] "data.table" "data.frame"
or
z <- setDT(data.frame(x))
class(z)
## [1] "data.table" "data.frame"