Thanks, that's very helpful!  Also, many thanks to Dimitris Rizopoulos and 
Robin Williams who both came up with good solutions to my problem.
 
Pall

-----Original Message-----
From: Henrique Dallazuanna [mailto:[EMAIL PROTECTED]
Sent: 12 September 2008 12:26
To: Jonsson, Pall
Cc: r-help@r-project.org
Subject: Re: [R] Finding a vector position using names rather than values


Try this:

order(row_median)[names(row_median) == "R3"]


On Fri, Sep 12, 2008 at 5:22 AM, Jonsson, Pall < [EMAIL PROTECTED]> wrote:


Dear R gurus,

I have been struggling with this for a while and thought you might be able to 
give me some guidance.

I have a data frame, on which I apply a row function.  The result looks to me 
like a vector that retains the old row names.  I then sort the vector and 
subsequently need to be able to identify the rank of certain values by 
searching for their row names.  See this mock example:

> dframe <- data.frame("Col1"=c(10,20,30), "Col2"=c(2,4,6), "Col3"=c(5,10,7), 
> row.names=c("R1","R2","R3"))
> row_median<-apply(dframe,1,median)
> row_median.sorted <- sort(row_median, decreasing=TRUE)

> row_median.sorted
R2 R3 R1
10  7  5

I now want to know the rank of, say R3 in this vector.  I know I can use 
match() to find this using the vector values, however I need to use the header 
names (eg. "R3") rather than the value (7).

Many thanks for your help,
Pall

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to