What is the R equivalent of the "except" function?

I have two datasets, df1 and df2, having the same number of columns and the same header. I want to remove all rows in df1 that are also present in df2. In SQL, I’d use the function except. df1 except df2.

What is the equivalent of except in R?

df1:

cust_id
1
2
3

df2

cust_id
1
2

df1 except df2 would result in:

cust_id
3

>Solution :

You can use setdiff

df1 <- setdiff(df1, df2)

df1
#>   cust_id
#> 1       3

Leave a Reply