Home > Blockchain >  How to filter not %in%?
How to filter not %in%?

Time:04-07

I have a dataframe df with an ID column. I use the following code to filter the values of df contained in a vector of ID:

df <- df %>% 
  filter(ID %in% vector)

How can I filter to get all the df values that have ID not contained in vector instead than contained in vector?

CodePudding user response:

Use ! to invert a condition:

df <- df %>% 
  filter(! ID %in% vector)
  •  Tags:  
  • r
  • Related