我正在寻找一种更快,更智能的方法来对具有多个条件且键/标识不是唯一的一列进行过滤。这是我的示例:
id <- c(1,1,2,3,4,4)
color <- c("blue","green","blue","green","blue","green")
data <- data.frame(id, color)
data1 <- data %>% filter(color %in% c("blue"))
data2 <- data %>% filter(color %in% c("green"))
data1_drop <- data1 %>% select(-color)
data2_drop <- data2 %>% select(-color)
final <- intersect(data1_drop,data2_drop)