Skip to Content

creating new dataframe with matching ids in two different table that do not match

I am trying to merge two dataframes with ids, I want to merge first all the ids that match and then find that doesn't match, I found the merge function which can merge the common ids.for example:

m1 = merge(df1, df2, by=c("id"))

Now I am trying to create a new dataframe with ids of dataframe 2 that do not match dataframe 1.

Could you please advise me which command should I look for?

For example:

I have the following two datasets:

df1
df2

I am trying to create a new dataframe with ids from df2 that not in df1. for example id = "a3" and "c3" in df2.

my sample data:

    df1 =data.frame(id= c("a1","a2","b1","b2","c1","c2"), value= 1:6)
df2 =data.frame(id= c("a1","a2","a3","b1","c1","c3"), value= 7:12)

Many thanks, Ayan