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 8742769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:33:27+00:00 2026-06-13T11:33:27+00:00

When I say unexpected, I mean unexpected for me. Allow me to illustrate. We

  • 0

When I say unexpected, I mean unexpected for me. Allow me to illustrate. We have the two data.frames:

b1<-data.frame(a=c("a","b"),b=1:2)
b2<-data.frame(a=c("a","b"),c=1:2)

Merge produces the following

> merge(b1,b2)
  a b c
1 a 1 1
2 b 2 2

But when we have the data.frames

b1<-data.frame(a=c("a","a"),b=1:2)
b2<-data.frame(a=c("a","a"),c=1:2)

merge produces the

> merge(b1,b2)
  a b c
1 a 1 1
2 a 1 2
3 a 2 1
4 a 2 2

when I expect

  a b c
  a 1 1
  a 2 2

Why the two different results?

  • 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-13T11:33:28+00:00Added an answer on June 13, 2026 at 11:33 am

    This is by design. base merge uses match on columns specified (or not specified). In case 1, it found only a single match for each value of a so there were no duplicates. But in case 2, it found two matches:

    > b1$a %in% b2$a 
    [1] TRUE TRUE  
    

    for each a and therefore returned all possible matches. See ?merge for more information. join in plyr has the option of matching only the first match.

    > join(b1,b2, match="first")
    Joining by: a
      a b c
    1 a 1 1
    2 a 2 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Should application expect the unexpected when fetching data from database? Lets say that we
Let's say I have two files file1.php and file2.php . file1.php has the following
Say I have a select box eg <div data-bind='visible: someProp'> <select class=selectSubWidgets data-bind='options: subWidgets,optionsText:
Say i have a few fields like the following: abd738927 jaksm234234 hfk342 ndma0834 jon99322
I am using xquery over BaseX XML Database. Say, I have the following documents
Say i have the following class : class Abc { int id; public: int
first of all, i like to say that i have read the other two
in one of my viewcontroller, lets say A, I have the following: OnbViewController *on
Say I have a Telerik MVC Grid, AJAX bound and I want to put
Say we have deep hashes like: b = {1 => {2 => {} },

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.