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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:22:42+00:00 2026-06-10T02:22:42+00:00

I have a matrix df<-matrix(data=c(3,7,5,0,1,0,0,0,0,8,0,9), ncol=2) rownames(df)<-c(a,b,c,d,e,f) [,1] [,2] a 3 0 b 7

  • 0

I have a matrix

df<-matrix(data=c(3,7,5,0,1,0,0,0,0,8,0,9), ncol=2)
rownames(df)<-c("a","b","c","d","e","f")

[,1] [,2]
a    3    0
b    7    0
c    5    0
d    0    8
e    1    0
f    0    9

and I would like to order the matrix in descending order first by column 1 and then by column two resulting in the matrix

df.ordered<-matrix(data=c(7,5,3,1,0,0,0,0,0,0,9,8),ncol=2)
rownames(df.ordered)<-c("b","c","a","e","f","d")

   [,1] [,2]
 b    7    0
 c    5    0
 a    3    0
 e    1    0
 f    0    9
 d    0    8

Any suggestions on how I could achieve this? Thanks.

  • 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-10T02:22:43+00:00Added an answer on June 10, 2026 at 2:22 am

    The order function should do it.

    df[order(df[,1],df[,2],decreasing=TRUE),]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a matrix of one column and 6 rows. I would like to
I have a matrix of data (with row names and column names). I would
I have matrix (a) with (1:10),<10 x 1> double. I would like to copy
I have a std::istream which refers to matrix data, something like: 0.0 1.0 2.0
I have 2 matrix structs means equal data but have different form like these:
I have to scan a Data Matrix written on something like this . The
I have a string matrix filled with data like matrix = ['1231231.jpeg','4343.jpeg',...] and I
I have a matrix (Data) which looks like this: (start) (stop) (strand) (gene number)
I have a matrix of data with column and row names, as such: Col1
I have a large data matrix with 5 columns. 5th column contains many zeros.

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.