Skip to content

Instantly share code, notes, and snippets.

@romainfrancois
Last active April 10, 2018 15:41
Show Gist options
  • Save romainfrancois/114a6788fa70aea92d7dbd8e67a2d07f to your computer and use it in GitHub Desktop.
Save romainfrancois/114a6788fa70aea92d7dbd8e67a2d07f to your computer and use it in GitHub Desktop.
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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment