When dplyr::mutate is used on a grouped data.table, the grouping is subsequently lost. This behavior does not occur for data.frame. Is this a bug? I am using dplyr_0.4.1 and data.table_1.9.4.
require(data.table)
require(dplyr)
by_cyl_df <- group_by( mtcars, cyl ) %>%
dplyr::mutate( . ,
maxmpg = max( mpg )
)
groups( by_cyl_df )
[[1]] cyl
by_cyl_dt <- group_by( as.data.table(mtcars), cyl ) %>%
dplyr::mutate( . ,
maxmpg = max( mpg )
)
groups( by_cyl_dt )
NULL
This is an open dplyr issue. After a
mutate
, the groups are dropped. If you look at the classes you can see this happening.And since it's no longer grouped (the
groups_dt
class is dropped), thegroups
function returns NULL for this type of object