R func that check if a value is in a df

Hi

i need to run some ID's though a ban list and return a list where they are deleted

ID:
structure(list(ID = c(595119208, 595174634, 210018628, 355597680
)), class = "data.frame", row.names = c(NA, -4L))

i got this ban list

structure(list(customer = c("Royal Netherlands Navy", "Royal Shipping And Trading Company Limited",
"Royalmar Denizcilik Ve Gemi Isletmeciligi Ltd Sirk", "Royalty Marine Limited",
"Royalty Petroleum Trading FZC", "Roymar Ship Management Incorporated"
), ID = c("BHC01815", "556003356", "355597680", "BHC07175", "557938947",
"BHC01816")), row.names = c(NA, -6L), class = c("tbl_df", "tbl",
"data.frame"))

and i want a list of the traders where the customers from the ban list is removed. how to make that function?

tried :
within(!which(sample$ID %in% non_Trade$ID))
not working

the python code that i want matched in R

def check_non_trader(df1,df2):

cond = df1['CustomerID'].isin(df2["CustomerID"])

df1.drop(df1[cond].index, inplace = TRUE)

Hi jak,

I think you could use an anti_join() to achieve the same effect.

library(dplyr)

df1 %>%
     anti_join(df2, by = "CustomerID")

And if you want to use similar syntax with python, you could try something like:

df1["CustomerID"] %in% df2["CustomerID"]

sample %>%

  • anti_join(non_Trade, by = "ID")

get the error
Error: Can't combine ID and ID .

ahh converted both to factors :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.