Output of many function in dplyr pkg is a tbl_df class objects. It is not handled correctly by setDT which works on regular df and lists very well. See below:
packageVersion("dplyr")
# [1] ‘0.4.1’
packageVersion("data.table")
# [1] ‘1.9.5’
library(dplyr) # latest CRAN
library(data.table) # latest dev
df <- data.frame(a = rnorm(1000), b = sample(1:5,1000,TRUE))
class(df)
# [1] "data.frame"
df2 <- as.tbl(df)
class(df2)
# [1] "tbl_df" "tbl" "data.frame"
setDT(df2)
class(df2)
# [1] "tbl_df" "tbl" "data.table" "data.frame"
Would be great to have setDT works on tbl_df and possibly also tbl classes.
Currently such object is not usable without using first setDT(as.data.frame(df2))[].
Edit
Or easier/faster operating directly on class attribute: setattr(df,"class",c("data.table","data.frame"))
Output of many function in dplyr pkg is a
tbl_dfclass objects. It is not handled correctly bysetDTwhich works on regular df and lists very well. See below:Would be great to have
setDTworks ontbl_dfand possibly alsotblclasses.Currently such object is not usable without using first
setDT(as.data.frame(df2))[].Edit
Or easier/faster operating directly on class attribute:
setattr(df,"class",c("data.table","data.frame"))