Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,690 questions

55,449 answers

573 users

How to sort specific column in descending order data frame with R

1 Answer

0 votes
df = data.frame(a = c(4, 7, 1, 3),
                b = c(98, 12, 87, 20),
                c = c(2, 4, 5, 9),
                d = c(13, 77, 50, 20),
                row.names = c('o', 'p', 's', 't'))
  
print(df)
  
df <- df[with(df, order(-a)), ]

print(df)
  
  
  
        
        
# run:
#
#   a  b c  d
# o 4 98 2 13
# p 7 12 4 77
# s 1 87 5 50
# t 3 20 9 20
#   a  b c  d
# p 7 12 4 77
# o 4 98 2 13
# t 3 20 9 20
# s 1 87 5 50
#

 



answered Jul 10, 2021 by avibootz

Related questions

1 answer 233 views
1 answer 262 views
262 views asked Jul 10, 2021 by avibootz
1 answer 315 views
1 answer 227 views
227 views asked Jul 9, 2021 by avibootz
1 answer 265 views
1 answer 240 views
1 answer 168 views
...