devtools::install_github("tidyverse/dplyr", ref = "feature-341-zero-length-groups")
# [...]
library(dplyr)
# [...]
d <- data_frame(
f = factor(c("a", "b"), levels = c("a", "b", "c")),
x = 1:2
)
tally( group_by(d, f, x, drop = FALSE) )
#> # A tibble: 6 x 3
#> # Groups: f [?]
#> f x n
#> <fct> <int> <int>
#> 1 a 1 1
#> 2 a 2 0
#> 3 b 1 0
#> 4 b 2 1
#> 5 c 1 0
#> 6 c 2 0
tally( group_by(d, x, f, drop = FALSE) )
#> # A tibble: 6 x 3
#> # Groups: x [?]
#> x f n
#> <int> <fct> <int>
#> 1 1 a 1
#> 2 1 b 0
#> 3 1 c 0
#> 4 2 a 0
#> 5 2 b 1
#> 6 2 c 0
Created on 2018-04-10 by the reprex package (v0.2.0).