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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:15:41+00:00 2026-06-05T20:15:41+00:00

I have two dataframes with the same number of columns. I’m writing a function

  • 0

I have two dataframes with the same number of columns. I’m writing a function that takes the two dataframes and an integer n as arguments and needs to sort each dataset by its respective nth column. Essentially, how can I sort a dataframe by it’s nth column without having to know the label of that column?

  • 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-05T20:15:42+00:00Added an answer on June 5, 2026 at 8:15 pm

    A slight modification to an answer here:
    How to sort a dataframe by column(s)?

    dd <- data.frame(b = factor(c("Hi", "Med", "Hi", "Low"), 
                                levels = c("Low", "Med", "Hi"), ordered = TRUE),
                     x = c("A", "D", "A", "C"), y = c(8, 3, 9, 9),
                     z = c(1, 1, 1, 2))
    
    n <- 2
    dd[ order(dd[[n]]), ]
    
    
        b x y z
    1  Hi A 8 1
    3  Hi A 9 1
    4 Low C 9 2
    2 Med D 3 1
    

    Alternatively, you could just look up the label with colnames(dd)[n] and use that with any of the methods in the above link.

    • 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: A and B of the same number of columns
Is it possible to row bind two data frames that don't have the same
I have tried the merge function to merge two csv files that I imported.
I have dataframe that was created from the fusion of two dataframes. Both spanned
Suppose we have the contents of tables x and y in two dataframes in
I have two data frames with two columns each. The first column is timestamps
I have a various data.frames with columns of the same length where I am
I have two data frames, Data1 and Data2, that I want to merge based
I have a list L of data frames with two columns each...a key, and
I've got two dataframes that look like this: ==fileA LmjF.01 257506 257508 1 LmjF.01

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.