[R] Sort (indices only)

rkevinburton at charter.net rkevinburton at charter.net
Mon Sep 8 19:38:20 CEST 2008


I am using the function 'spectrum'. It returns two arrays that are interesting to me. One would be the wieght or density of a given frequency with the irequency given in another array. I would like to take the top 'n' weights which would be the top 'n' frequencies contributing to the signal. One way to do this would be to use 'sort' which would sort the weights but I then lose which frequency that weight corresponds to. What would be the best was to get the top 'n' indices in the weight (spec) array so I can use these to index the corresponding frequency?

In general this would be an indirect sort where the returned array is an array of indices.

Thank you.

Kevin



More information about the R-help mailing list