r - Why doesn't setDT have any effect in this case? -


consider following code

library(data.table) # 1.9.2 x <- data.frame(letters[1:2])  setdt(x)  class(x) ## [1] "data.table" "data.frame" 

which expected result. if run

x <- letters[1:2] setdt(data.frame(x))  class(x)  ## [1] "character" 

the class of x remained unchanged reason.

one possibility setdt changes classes of objects in global environment, i've tried

x <- data.frame(letters[1:2])  ftest <- function(x) setdt(x)  ftest(x)  class(x)  ##[1] "data.table" "data.frame" 

seems setdt don't care environment of object in order change class.

so what's causing above behaviour? bug or there common sense behind it?

setdt changes data.frame , returns invisibly. since don't save data.frame, lost. need somehow save data.frame, data.table 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" 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -