Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8000897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:56:26+00:00 2026-06-04T15:56:26+00:00

I am trying to merge two dataframes with ids, I want to merge first

  • 0

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:

enter image description here df1
enter image description heredf2

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

enter image description here

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:56:27+00:00Added an answer on June 4, 2026 at 3:56 pm

    If you want to use merge, here is one way to do it:

    df_merged <- merge(df2, df1, by.x="id", by.y="id", all.x=TRUE)
    df_merged[is.na(df_merged$value.y),]
      id value.x value.y
    3 a3       9      NA
    6 c3      12      NA
    

    Since your column names are in both data.frames identical and merge merges by common column names, you have to tell the function the column names explicitly that you want to use, here id.

    But you should ask yourself if you really want to merge here? If you just want those rows in df2 that are not in df1, why not use something like this?

    df2[!(df2$id %in% df1$id), ]
      id value
    3 a3     9
    6 c3    12
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi im trying to merge two tables. I have ids that exists only in
I'm trying to merge two arrays for the values of array1 that are set
I'm trying to merge two file that have the same structure, and some data
I'm trying to merge two arrays that have some overlapping results and some that
Im trying to find simplest way to merge two arrays into the third one,
I'm trying to write a program that merge two or more .dat files in
I am trying to merge two hashtables, overwriting key-value pairs in the first if
I am trying to merge two data.frames together, based on a common column name
I'm trying to merge two docx-documents into one docx-document using OpenXML SDK 2.0. The
im trying to merge two arrays together. both have numeric keys and are unique.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.