R: remove rows from one data frame that are in another

r

Solution

You can do that with several packages. But here's how to do it with base R.

df1 <-matrix(1:6,ncol=2,byrow=TRUE)
df2 <-matrix(1:10,ncol=2,byrow=TRUE)
all <-rbind(df1,df2) #rbind the columns
#use !duplicated fromLast = FALSE and fromLast = TRUE to get unique rows.
all[!duplicated(all,fromLast = FALSE)&!duplicated(all,fromLast = TRUE),] 

     [,1] [,2]
[1,]    7    8
[2,]    9   10

Problem

I have two data frames df1 and df2. They have the same (two) columns. I want to remove the rows from df1 that are in df2.

Original source

Related problems