筛选多列的基础

时间:2020-06-23 16:56:50

标签: r filter dplyr tidyverse

是否可以过滤其他3列中存在的一列的值?

一个长远的解决方案是做到这一点

filter(Names1 %in% Names2| Names1 %in% Names3| Names1 %in% Names4)

是否有使用dplyr的更快方法?

类似的东西

filter(Names1 %in% (Names2| Names3 | Names4)

谢谢

我。

2 个答案:

答案 0 :(得分:2)

您可以使用c()组合正在查找的列:

df %>%
  filter(Names1 %in% c(Names2, Names3, Names4))

答案 1 :(得分:0)

base R中,我们可以使用subset

subset(df, Names1 %in% c(Names2, Names3, Names4))