简体   繁体   English

如何删除包含另一个数据框中列的元素的行

[英]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我想排除Namefirst_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.

相关问题 如何从 R 中的数据框中删除指定行,但根据另一个列变量消除行? - How do I remove specified rows from a data frame in R, but the rows are eliminated according to another column variable? 在R中,如何通过另一个数据框的列名删除数据框中的行? - In R, how do I delete rows in a data frame by column names of another data frame? 如何根据 R 中数据框中的某些列和行信息删除唯一行 - How do I remove unique rows based on certain column and row information in a data frame in R 比较数据框中某列中的元素与另一数据框中同一列中的另一个元素以获取R中的对应行 - comparing an element in a column in a data frame with another element in the same column in another data frame for corresponding rows in R 如何按数据帧中的列减少行数? - How do i cut down the number of rows by a column in a data frame? 如何从数据框中删除与 R 中单独数据框中唯一值相等的所有行? - How do I remove all rows from data frame that equal unique value in seperate data frame in R? 如何通过行 id 识别数据框列中的值而不是另一个数据框列中的值? - How do I Identify by row id the values in a data frame column not in another data frame column? 如何删除包含 NA 的数据框中的行,但为某些行保留例外? - How do I remove rows in a data frame that contain NAs but leave exceptions for certain rows? 如何将一个数据框中的行移动到另一数据框中的列? - How do I move a row in one data frame to a column in another data frame? 如何对共享另一列中给出的相同ID的所有行在数据框中标准化列值? - How can I normalize column values in a data frame for all rows that share the same ID given in another column?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM