[R] ordering a data.frame by average rank of multiple columns
ggrothendieck at gmail.com
Fri Aug 10 13:36:11 CEST 2007
positions <- order(ranks)
On 8/10/07, Tom.O <tom.olsson at dnbnor.com> wrote:
> I have run into a problem and i wonder if anyone has a smart way of doing
> For example i have this data frame for 5 different test groups:
> Res1 <- c(1,5,4,-0.5,3)
> Res2 <- c(-1,8,2,0,3)
> Mean <- c(0.5,1,1.5,-.5,2)
> MyFrame <- data.frame(Res1,Res2,Mean,row.names=c("G1","G2","G3","G4","G5"))
> where the first two columns are the results of two different tests, the
> third column is the mean of the group.
> I want to order this data.frame by the combined rank of Res1 & Res2, but
> where weigths are assigned to the importeance av each column. Lets assume
> that Res1 is twice as important and lower values rank better.
> Rank1 Rank2 CombR
> G1 2 1 5
> G2 5 5 15
> G3 4 3 11
> G4 1 2 4
> G5 3 4 10
> and the rank of the combined is 2,5,4,1,3 , but to be able to sort MyFrame
> in that order I need to enter this vector of positions c(4,1,5,3,2) but do
> anyone have a smart way of converting ranks to positions?
> View this message in context: http://www.nabble.com/ordering-a-data.frame-by-average-rank-of-multiple-columns-tf4247393.html#a12087498
> Sent from the R help mailing list archive at Nabble.com.
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help