-1
HospitalName                       | Rating
-----------------------------------|  ------
FORT DUNCAN MEDICAL CENTER         | 8.1
TOMBALL REGIONAL MEDICAL CENTER    | 8.5
DETAR HOSPITAL NAVARRO             | 8.7
CYPRESS FAIRBANKS MEDICAL CENTER   | 8.7

Here is my sample table , you can see In Hospital Name "DETAR HOSPITAL" and "Cypress FAIRBANKS " Having the same Rating . I have sorted the table by the least rating to highest rating but all I need is sort the Hospital Names alphabetically which have the same Rating, like "CYPRESS..." Should come first then "DETAR" though they having the same Rating but they need to be arranged alphabetically .

Can any one help me with this ?

Jaap
  • 71,900
  • 30
  • 164
  • 175
Sumanth Sharma
  • 135
  • 2
  • 15

1 Answers1

0

We can use order

df1[order(df1$Rating, df1$HospitalName),]
#                      HospitalName Rating
#1       FORT DUNCAN MEDICAL CENTER    8.1
#2  TOMBALL REGIONAL MEDICAL CENTER    8.5
#4 CYPRESS FAIRBANKS MEDICAL CENTER    8.7
#3           DETAR HOSPITAL NAVARRO    8.7

If we are using dplyr, arrange is the way to go

library(dplyr)
df1 %>%
   arrange(Rating, HospitalName)
akrun
  • 674,427
  • 24
  • 381
  • 486