13

我有一个包含 2 列的数据框。我已经使用order()功能订购了它们

data<-data[order(data$Mortality),]
head(data)

                       Hospital.Name     Mortality
 FORT DUNCAN MEDICAL CENTER                      8.1
 TOMBALL REGIONAL MEDICAL CENTER                 8.5
 DETAR HOSPITAL NAVARRO                          8.7
 CYPRESS FAIRBANKS MEDICAL CENTER                8.7
 MISSION REGIONAL MEDICAL CENTER                 8.8
 METHODIST HOSPITAL,THE                          8.8

第 3 和第 4 位是平局(Mortality两者 = 8.7)。我想按字母顺序打破平局,data$Hospital.Name以便“CYPRESS FAIRBANKS”排在第 3 位,“DETAR HOSPITAL”排在第 4 位。

4

1 回答 1

20

用作data$Hospital.Name第二个参数order

R> data <- data[order(data$Mortality, data$Hospital.Name), ]
R> data
                     Hospital.Name Mortality
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
6           METHODIST HOSPITAL,THE       8.8
5  MISSION REGIONAL MEDICAL CENTER       8.8
于 2013-01-18T07:47:43.450 回答