[英]How do I remove specified rows from a data frame in R, but the rows are eliminated according to another column variable?
[英]how do I remove rows that contains an element of a column in another data frame
我有一個數據框,其中包含我不想包含在最終數據框中的行。 但我不知道如何排除它們。 我嘗試了一些東西,但沒有奏效,我在 web 上找不到合適的答案。
first_filtered_list<- data%>%filter(Name == old_name & NUMBER_OF_LOCATIONS != PREVIEW_NUM)
此列表包含我想從數據中排除的所有行。 我無法將其更改為first_filtered_list<- data%>%filter(Name == old_name & NUMBER_OF_LOCATIONS == PREVIEW_NUM)
因為數據有數百個重復名稱。 我想排除Name
在first_filtered_list$Name
中的所有行
您可以在要過濾的列上使用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'))
但是你為什么不直接過濾你的數據呢?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.