MGF
MGF

Reputation: 41

How to apply filter when one condition is a list of values

I want to filter the values of data frame (A) which does not meet a a condition. This condition is the content of a column of other data frame (B). So the filtering should return values of the data frame (A) which are not included in the column of the data frme (B). I have found a possible method to do it without applying the function filter, but I would like to know if it is possible to do something similar using this function. Find below the method without using filter:

df<-df[!(df$Wind %in% g_caja$out),]

df$Wind should be data frame A

g_caja$out should be data frame B

Upvotes: 0

Views: 1025

Answers (1)

akrun
akrun

Reputation: 887098

The filter can use the same logic

library(dplyr)
df %>%
     filter(!Wind %in% g_caja$out)

Or another option is anti_join

anti_join(df, g_caja, by = c("Wind" = "out"))

Upvotes: 2

Related Questions