[R] Finding a vector position using names rather than values
Jonsson, Pall
Pall.Jonsson at astrazeneca.com
Fri Sep 12 10:22:25 CEST 2008
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
More information about the R-help
mailing list