This seems like a very common task, but I can't find a solution in google or SO. I want to add the "rank" column to "dat1" based on the sequence that "order.scores" refers to "dat". I tried using row.names (), but the growth names are based on 'dat', not 'dat1'. I also tried 'dat $ rank <-rank (dat1)', but this causes an error message.
fname<-c("Joe", "Bob", "Bill", "Tom", "Sue","Sam","Jane","Ruby")
score<-c(500, 490, 500, 750, 550, 500, 210, 320)
dat<-data.frame(fname,score)
order.scores<-order(dat$score,dat$fname)
dat1<-dat[order.scores,]
source
share