[英]how do I remove rows that contains an element of a column in another data frame
I have a data frame with rows I do not want to include in the final data frame.我有一个数据框,其中包含我不想包含在最终数据框中的行。 But I do not know how to exclude them.但我不知道如何排除它们。 I tried some stuff but it didn't work and I couldn't find a fitting answer on the web.我尝试了一些东西,但没有奏效,我在 web 上找不到合适的答案。
first_filtered_list<- data%>%filter(Name == old_name & NUMBER_OF_LOCATIONS != PREVIEW_NUM)
This list contains all rows I want to exclude from the data.此列表包含我想从数据中排除的所有行。 I can't change it to first_filtered_list<- data%>%filter(Name == old_name & NUMBER_OF_LOCATIONS == PREVIEW_NUM)
because the data has hundreds of duplicate names.我无法将其更改为first_filtered_list<- data%>%filter(Name == old_name & NUMBER_OF_LOCATIONS == PREVIEW_NUM)
因为数据有数百个重复名称。 I would like to exclude all rows whose Name
is in the first_filtered_list$Name
我想排除Name
在first_filtered_list$Name
中的所有行
You could use a anti_join
on the columns you want to filter?您可以在要过滤的列上使用anti_join
吗?
library(dplyr)
df1 <- data.frame(a=1:5, b=letters[1:5], c=runif(5))
df_to_filter <- df1[c(1,3,5),]
df1 %>% anti_join(df_to_filter, by=c('a','b'))
But why don't you directly filter your data?但是你为什么不直接过滤你的数据呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.