It seems like some dplyr
functions, including mutate_if
, mutate_all
, mutate_at
etc coerce data.table inputs to data.frame. That seems like strange behaviour, even though it is documented in ?mutate_all
(Under 'Value', it says 'data.frame' - but it does not coerce tibbles to data.frames.)
require(dplyr)
require(data.table)
data("iris")
dt <- as.data.table(iris)
class(dt)
#[1] "data.table" "data.frame"
class(mutate_if(dt, is.numeric, as.numeric))
#[1] "data.frame"
However, this does not happen with tibbles:
tb <- as_tibble(iris)
class(tb)
#[1] "tbl_df" "tbl" "data.frame"
class(mutate_if(tb, is.numeric, as.numeric))
#[1] "tbl_df" "tbl" "data.frame"
Is there some way to maintain the data.table, or do i need to coerce with as.data.table
every time I use one of the scoped mutate
functions?
data.table
is not a base class, it returnsdata.frame
– Rohit