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

  • Home
  • SEARCH
  • 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 1031477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:56:08+00:00 2026-05-16T13:56:08+00:00

I have two data.frames in R, one of which has two columns and of

  • 0

I have two data.frames in R, one of which has two columns and of the other of each has three columns, and where two columns are common between the two frames. The frame have the same number of rows. An example of the frames, a and b, is provided below. What I need to do is reorder the rows of b using the order of rows in a. Note that in frame b, any unique combination of the first two columns, id and lob, will be associated with a unique value in the val column. The id and lob columns given here are a factor and a character, but I would want a solution to work for any datatype.

Note that if we were to consider a case where frame a just had the id column and frame b just had the id and val columns, I would accomplish this with something like

b[match(a$id,b$id),]

Unfortunately, I’m not sure how to accomplish the same thing when I need to order by two columns.

a:

  id lob
1 1+   X
2  3   X
3  2   X
4  1   X
5  1   Y
6 1+   Y
7 1+   X
8  3   X
9  3   X

b:

  id lob val
1 1+   X   1
2 1+   Y   9
3 1+   X   1
4  3   X   5
5  3   X   5
6  3   X   5
7  2   X   4
8  1   X   3
9  1   Y   2

I want to get this:

  id lob val
1 1+   X   1
2  3   X   5
3  2   X   4
4  1   X   3
5  1   Y   2
6 1+   Y   9
7 1+   X   1
8  3   X   5
9  3   X   5
  • 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-05-16T13:56:09+00:00Added an answer on May 16, 2026 at 1:56 pm

    Try using paste to combine your id and lob within your merge function call.

    b[match(paste(a$id,a$lob), paste(b$id,b$lob)),]
    
    
        id lob val
    1   1+   X   1
    4    3   X   5
    7    2   X   4
    8    1   X   3
    9    1   Y   2
    2   1+   Y   9
    1.1 1+   X   1
    4.1  3   X   5
    4.2  3   X   5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two data frames. The one consists of three variables, namely date, strike
I have my old data model, my new model (same but with two more
I have two UILabels in a XIB file, one on top of the other,
How can I read the delay, left and top offset data for each frame
I have implemented a custom UITableViewCell which includes a UITextView that auto-resizes as the
I want to plot data from different data frames with ggplot. However, I'm having
I want to mix two (or more) 16bit audio streams using OpenGL and I
This is a problem that comes up often when I am importing raw data
I've enabled wcf basicHttpBinding with TransferMode set to Streaming. The problem is every time
When you write a dissector for Wireshark, how do you test it? Looking for

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.