具有多个条件和或的dplyr过滤器

具有多个条件和或的dplyr过滤器,r,filter,dplyr,tidyverse,R,Filter,Dplyr,Tidyverse,我有一个很大的tibble,我需要通过过滤来减少它。具体来说,我需要过滤多个条件的不同组合(但都来自同一列) 我的过滤条件类似于 filter(str_detect(id, "^M.+(KIT|FLEECE)"), between(f1, 300, 400), between(f2, 1300, 1400)) filter(str_detect(id, "^M.+(GOOSE)"), between(f1, 200, 350), between(f2, 1200, 1400)) fi

我有一个很大的tibble,我需要通过过滤来减少它。具体来说,我需要过滤多个条件的不同组合(但都来自同一列)

我的过滤条件类似于

  filter(str_detect(id, "^M.+(KIT|FLEECE)"), between(f1, 300, 400),  between(f2, 1300, 1400))
 filter(str_detect(id, "^M.+(GOOSE)"), between(f1, 200, 350),  between(f2, 1200, 1400))
filtered1<- df %>%
  filter(str_detect(id, "^M.+(KIT|FLEECE)"), between(f1, 300, 400),  between(f2, 1300, 1400))
filtered2<- df %>%
  filter(str_detect(id, "^M.+(GOOSE)"), between(f1, 200, 350),  between(f2, 1200, 1400))
filtered<-bind_rows(filtered1, filtered2)     
当然是这样的

  filter(str_detect(id, "^M.+(KIT|FLEECE)"), between(f1, 300, 400),  between(f2, 1300, 1400))
 filter(str_detect(id, "^M.+(GOOSE)"), between(f1, 200, 350),  between(f2, 1200, 1400))
filtered1<- df %>%
  filter(str_detect(id, "^M.+(KIT|FLEECE)"), between(f1, 300, 400),  between(f2, 1300, 1400))
filtered2<- df %>%
  filter(str_detect(id, "^M.+(GOOSE)"), between(f1, 200, 350),  between(f2, 1200, 1400))
filtered<-bind_rows(filtered1, filtered2)     
filtered1%
过滤器(str_-detect(id,“^M.+(KIT | FLEECE)”)、介于(f1、300、400)之间、介于(f2、1300、1400)之间)
过滤器2%
过滤器(str_检测(id“^M.+(GOOSE)”),介于(f1、200、350)之间,介于(f2、1200、1400)之间)

过滤您可以使用
&
将它们放在括号中,然后使用管道
|
表示“或”

df%>%
滤器(
(str_-detect(id,“^M.+(KIT | FLEECE)”)&介于(f1、300、400)和(f2、1300、1400)之间)|
(str_detect(id,“^M.+(GOOSE)”)&介于(f1、200、350)和(f2、1200、1400)之间)
)