tidyverse / dtplyr

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

Properly handle groups in `count()` #358

Closed markfairbanks closed 2 years ago

markfairbanks commented 2 years ago

Closes #356

Edit: Worth mentioning for this review - count() and tally() approach groups differently. tally() follows the summarize(.groups = "drop_last") idea.

library(dplyr)

df <- tibble(x = c("a", "a", "b"), y = c("a", "a", "b"))

df %>%
  group_by(x, y) %>%
  count()
#> # A tibble: 2 × 3
#> # Groups:   x, y [2]
#>   x     y         n
#>   <chr> <chr> <int>
#> 1 a     a         2
#> 2 b     b         1

df %>%
  group_by(x, y) %>%
  tally()
#> # A tibble: 2 × 3
#> # Groups:   x [2]
#>   x     y         n
#>   <chr> <chr> <int>
#> 1 a     a         2
#> 2 b     b         1