According to the dplyr docs, add_count() is supposed to:
group transiently, so the output has the same groups as the input.
Although this is true for the dplyr version, I discovered that the dbplyr version does change the groups.
library(tidyverse)
library(dbplyr)
df <- tribble(
~name, ~gender, ~runs,
"Max", "male", 10,
"Sandra", "female", 1,
"Susan", "female", 4
)
# ungrouped output
df %>% add_count(gender, wt = runs)
#> # A tibble: 3 x 4
#> name gender runs n
#> <chr> <chr> <dbl> <dbl>
#> 1 Max male 10 10
#> 2 Sandra female 1 5
#> 3 Susan female 4 5
# grouped output
memdb_frame(df) %>% add_count(gender, wt = runs)
#> # Source: lazy query [?? x 4]
#> # Database: sqlite 3.34.1 [:memory:]
#> # Groups: gender
#> name gender runs n
#> <chr> <chr> <dbl> <dbl>
#> 1 Sandra female 1 5
#> 2 Susan female 4 5
#> 3 Max male 10 10
Created on 2021-03-11 by the reprex package (v1.0.0)
According to the dplyr docs,
add_count()is supposed to:Although this is true for the dplyr version, I discovered that the dbplyr version does change the groups.
Created on 2021-03-11 by the reprex package (v1.0.0)