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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:28:36+00:00 2026-06-14T12:28:36+00:00

I have two easy matrices (or df’s) to merge: a <- cbind(one=0:15, two=0:15, three=0:15)

  • 0

I have two easy matrices (or df’s) to merge:

a <- cbind(one=0:15, two=0:15, three=0:15)
b <- cbind(one=0:15, two=0:15, three=0:15)
#a <- data.frame(one=0:15, two=0:15, three=0:15)
#b <- data.frame(one=0:15, two=0:15, three=0:15)

No problem: after sorting on column one, column one is output ascending nicely from 0 to 15:

merge(a,b,by=c("one"), sort=T)
   one two.x three.x two.y three.y
1    0     0       0     0       0
2    1     1       1     1       1
3    2     2       2     2       2
4    3     3       3     3       3
5    4     4       4     4       4
6    5     5       5     5       5
7    6     6       6     6       6
8    7     7       7     7       7
9    8     8       8     8       8
10   9     9       9     9       9
11  10    10      10    10      10
12  11    11      11    11      11
13  12    12      12    12      12
14  13    13      13    13      13
15  14    14      14    14      14
16  15    15      15    15      15

But wait: when merging on two columns — both numeric — the sort order suddenly seems alphabetic.

merge(a,b,by=c("one", "two"), sort=T)
   one two three.x three.y
1    0   0       0       0
2    1   1       1       1
3   10  10      10      10
4   11  11      11      11
5   12  12      12      12
6   13  13      13      13
7   14  14      14      14
8   15  15      15      15
9    2   2       2       2
10   3   3       3       3
11   4   4       4       4
12   5   5       5       5
13   6   6       6       6
14   7   7       7       7
15   8   8       8       8
16   9   9       9       9

Eww, gross. What’s going on? And what do I do?

  • 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-14T12:28:37+00:00Added an answer on June 14, 2026 at 12:28 pm

    Based on @joran’s comments, it looks like if you want the rows to be sorted in any particular order, you should explicitly set it yourself.

    If the order you’d like is one in which the rows have increasing values of one or more columns, you can use the function order(), like this:

    X <- merge(a, b, by = c("one", "two"))
    X[with(X, order(one, two)),]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two matrices a and b of 1 column and n rows. These
The problem is easy to explain: we have two big arrays (32 bit integer
This one's probably easy: I have two variables: $sender_id $receiver_id Those ID's are stored
guys I have two question to ask, they're easy, but bothering me for a
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two classes (MVC view model) which inherits from one abstract base class.
I have two quick, easy questions on C# in Visual Studio. First, is there
I have what should be an easy question for you today. I have two
I have two examples on jsFiddle: http://jsfiddle.net/9uhfX/1/ http://jsfiddle.net/9uhfX/2/ Example 1 In the first one
I have two spreadsheets of data saved in separate Google spreadsheets, Stores and Products.

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.