group_modify() applies .f to each group, returning a modified lazy_dt(). This function is a little less flexible than the data.frame method due to the constraints of the code generation that dtplyr uses.

# S3 method for dtplyr_step
group_modify(.tbl, .f, ..., keep = FALSE)

Arguments

.tbl

A lazy_dt

.f

The name of a two argument function. The first argument is passed .SD,the data.table representing the current group; the second argument is passed .BY, a list giving the current values of the grouping variables. The function should return a list or data.table.

...

Additional arguments passed to .f

keep

Not supported for lazy_dt.

Examples

library(dplyr)
#> #> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’: #> #> filter, lag
#> The following objects are masked from ‘package:base’: #> #> intersect, setdiff, setequal, union
mtcars %>% lazy_dt() %>% group_by(cyl) %>% group_modify(head, n = 2L)
#> Source: local data table [?? x 11] #> Call: `_DT1`[, head(.SD, .BY, n = ~2L), keyby = .(cyl)] #> #> cyl mpg disp hp drat wt qsec vs am gear carb #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 4 22.8 108 93 3.85 2.32 18.6 1 1 4 1 #> 2 4 24.4 147. 62 3.69 3.19 20 1 0 4 2 #> 3 6 21 160 110 3.9 2.62 16.5 0 1 4 4 #> 4 6 21 160 110 3.9 2.88 17.0 0 1 4 4 #> 5 8 18.7 360 175 3.15 3.44 17.0 0 0 3 2 #> 6 8 14.3 360 245 3.21 3.57 15.8 0 0 3 4 #> #> # Use as.data.table()/as.data.frame()/as_tibble() to access results