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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:10:23+00:00 2026-06-12T19:10:23+00:00

I have a df : Years Company ID Name Return 2003 23 622009 a

  • 0

I have a df :

Years Company ID    Name    Return
2003    23  622009  a       2323123
2008    14  622008  v       2312343
2009    43  622007  c       35345345
2006    32  622006  d       45656554
2005    67  622005  f       756756766
1999    60  622004  y       4564533
2001    63  622003  i       6756766
2002    66  622002  m       32423412
2008    68  622001  o       934833833
2004    48  622000  e       34132222

I am trying to rearrange the ordering of the Years column in ascending order (so the most recent year (2009) is on the top). In example :

Years Company ID    Name    Return
2009    62  622007  c       35345345
2008    62  622008  v       2312343 
2008    62  622001  o       934833833 
2006    62  622006  d       45656554
2005    62  622005  f       756756766

and so on…

I tried to do it with a for loop but it gives an incorrect answer. I get only the last row :

2005    62  622005  f       756756766

for (i in 1:length(unique(df$Year))){
  mm<-df[df$Year==unique(df$Year)[i],]
}

Could someone please guide me what I am doing wrong?

  • 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-12T19:10:25+00:00Added an answer on June 12, 2026 at 7:10 pm

    Use order function for that:

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

Sidebar

Related Questions

Below I have table - Company id name value year 1 IBM 10 2011
I have a simple stupid question. Here's the problem, for years, my company has
Say you have a database that has served a company for 10 years. It
I've spent 4 years developing C++ using Visual Studio 2008 for a commercial company;
I have a driver that my company has been using for a few years
We have 3 years old solution (.sln) with about 20 projects (.csproj). It is
I have 5 years of work experience in developing WEB and WIN application using
I have 4 years experience on DotNet, not much. I now learned developing for
I have 100 years of monthly data where each month is a file and
In the following example I have two years worth of data denoted by data_2007

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.