tidyverse / dtplyr

Data table backend for dplyr
https://dtplyr.tidyverse.org
Other
670 stars 57 forks source link

Implement `consecutive_id()` #414

Closed markfairbanks closed 1 year ago

markfairbanks commented 1 year ago
library(dplyr, w = FALSE)

df <- tibble(x = c(1, 2, 2, 1, 1))

df %>%
  mutate(consecutive_id = consecutive_id(x),
         rleid = data.table::rleid(x))
#> # A tibble: 5 × 3
#>       x consecutive_id rleid
#>   <dbl>          <int> <int>
#> 1     1              1     1
#> 2     2              2     2
#> 3     2              2     2
#> 4     1              3     3
#> 5     1              3     3