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
If you want to use
merge, here is one way to do it:Since your column names are in both
data.framesidentical andmergemerges by common column names, you have to tell the function the column names explicitly that you want to use, hereid.But you should ask yourself if you really want to merge here? If you just want those rows in
df2that are not indf1, why not use something like this?