On 16-Sep-08, at 8:04 AM, Peng Jiang wrote:

 Dear R experts,

i have a vector z , i have to do something after z is sorted. how can i find the original index, i.e., before sorting, of a certain element in the sorted vector .
 thanks in advance

I use this function provided in the old "Blue Book".

sort.mat <-
function(mat1, col1)
{
        mat1[sort.list(mat1[, col1]),  ]
}

where "mat1" is the matrix to be sorted (in your case a n x 2 matrix of your vector and an index vector), and
"col1" is the column to be sorted on.

HTH


  regards
-----------------------------------------------
Peng Jiang 江鹏 ,Ph.D. Candidate


Don McKenzie, Research Ecologist
Pacific WIldland Fire Sciences Lab
US Forest Service

Affiliate Professor
College of Forest Resources
CSES Climate Impacts Group
University of Washington

desk: 206-732-7824
cell: 206-321-5966
[EMAIL PROTECTED]
[EMAIL PROTECTED]

______________________________________________
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