Open
Description
Printing a grouped tibble provides the grouping variables and number of groups. We should try to mirror that with grouped_epi_archive
s. Note that it gets messy with the use of .drop=FALSE
(especially with a mix of factor and non-factor grouping variables, which seems inadvisable).
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
tibble(g=c(1,1,1,2,3), a=c(1,2,2,2,2)) %>% group_by(g,a)
#> # A tibble: 5 × 2
#> # Groups: g, a [4]
#> g a
#> <dbl> <dbl>
#> 1 1 1
#> 2 1 2
#> 3 1 2
#> 4 2 2
#> 5 3 2
tibble(g=factor(letters[c(1,1,1,2,3)], letters[1:5]), a=c(1,2,2,2,2)) %>% group_by(g)
#> # A tibble: 5 × 2
#> # Groups: g [3]
#> g a
#> <fct> <dbl>
#> 1 a 1
#> 2 a 2
#> 3 a 2
#> 4 b 2
#> 5 c 2
tibble(g=factor(letters[c(1,1,1,2,3)], letters[1:5]), a=c(1,2,2,2,2)) %>% group_by(g, .drop=FALSE)
#> # A tibble: 5 × 2
#> # Groups: g [5]
#> g a
#> <fct> <dbl>
#> 1 a 1
#> 2 a 2
#> 3 a 2
#> 4 b 2
#> 5 c 2
tibble(g=factor(letters[c(1,1,1,2,3)], letters[1:5]), a=c(1,2,2,2,2)) %>% group_by(g,a, .drop=FALSE)
#> # A tibble: 5 × 2
#> # Groups: g, a [6]
#> g a
#> <fct> <dbl>
#> 1 a 1
#> 2 a 2
#> 3 a 2
#> 4 b 2
#> 5 c 2
tibble(g=factor(letters[c(1,1,1,2,3)], letters[1:5]), a=factor(c(1,2,2,2,2))) %>% group_by(g,a, .drop=FALSE)
#> # A tibble: 5 × 2
#> # Groups: g, a [10]
#> g a
#> <fct> <fct>
#> 1 a 1
#> 2 a 2
#> 3 a 2
#> 4 b 2
#> 5 c 2
Created on 2023-03-15 with reprex v2.0.2