Filter groups in dplyr that exclusively contain specific combinations of values

后端 未结 2 912
面向向阳花
面向向阳花 2020-12-10 05:57

Given a table like:

  id value
1  1     a
2  2     a
3  2     b
4  2     c
5  3     c

I would like to filter for:

a) the ids that o

2条回答
  •  粉色の甜心
    2020-12-10 06:33

    Try

    a)

    df %>% group_by(id) %>% filter(all(value == "a"))
    

    b)

    df %>% group_by(id) %>% filter(all(c("a", "b") %in% value))
    

提交回复
热议问题