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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:53:41+00:00 2026-06-13T17:53:41+00:00

data = c(1,2,3,4) names = c(foo, bar, baz, yak) d = data.frame(data, row.names=names) This

  • 0
data = c(1,2,3,4)
names = c("foo", "bar", "baz", "yak")
d = data.frame(data, row.names=names)

This returns:

    data
foo    1
bar    2
baz    3
yak    4

Now, I’d like to sort this dataframe by the column, without losing the row names attached. So, my result would be:

    data
yak    4
baz    3
bar    2
foo    1

I’ve already tried the following:

  • d[order(-d$data),], which of course only gives me the one-dimensional list.

  • arrange(d, desc(data)) from the plyr package, which drops the row names.

  • Find out the order with o = order(-d$data), then reconstruct the frame with

    data.frame(d[o,], row.names=rownames(d)[o])
    

    … which still leaves me with the wrong column name.

Is there any sane way to do this?

  • 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-13T17:53:42+00:00Added an answer on June 13, 2026 at 5:53 pm

    You were close with your first attempt, just forgot about using drop = FALSE:

    > d[order(-d$data), , drop = FALSE]
        data
    yak    4
    baz    3
    bar    2
    foo    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataframe structured like this: First A B Second bar baz foo
Given this: data Foo = Bar { name :: String } | Baz {
I've a data.frame with row.names as in test. test <- c(Env_1990:trait_KPS, Env_1990:trait_SPSM, Env_1990:trait_TKW, Env_1990:trait_Yield,
Consider the following data file: column_name foo foo bar baz baz bar foo baz
<?php class BaseClass { protected $data = array(foo => 0, bar => 0, baz
I have a data.frame with entries like: variable importance order 1 foo 0.06977263 1
I have a three column workbook with the following data: Col A: Names Col
I have a data bound listbox that lists names of items, I am now
How to retrieve data from two tables whose column names are the same?
I have a list of dictionaries like in this example: listofdict = [{'name': 'Foo',

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.