Skip to content

Need a way to respect .drop when using interact #134

@gergness

Description

@gergness

If you're grouping by an interact variable, it's not possible to avoid dropping missing levels.

library(srvyr)
data(api, package = "survey")
dstrata <- apistrat %>%
  as_survey_design(strata = stype, weights = pw)


dstrata %>% 
  filter(stype == "E") %>% 
  group_by(stype, .drop = FALSE) %>%
  summarize(n = survey_total())
#> # A tibble: 3 × 3
#>   stype     n  n_se
#>   <fct> <dbl> <dbl>
#> 1 E     4421.     0
#> 2 H        0      0
#> 3 M        0      0


dstrata %>% 
  filter(stype == "E") %>% 
  group_by(interact(stype), .drop = FALSE) %>%
  summarize(n = survey_total())
#> # A tibble: 1 × 3
#>   stype     n  n_se
#>   <fct> <dbl> <dbl>
#> 1 E     4421.     0

Created on 2021-11-07 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions