Skip to content

get the sorted index of elements within a column

2 messages · wendy, Dennis Murphy

#
Hi all,

I have matrix, A. I want to sort the elements in each column in a ascending
order and output the index number their position. For example

A = 

          [,1]     [,2]      [,3]       [,4]
[1,] 135.87060 97.55820 121.07722 171.625495
[2,]  70.19811 36.64529  50.13501   6.319125
[3,]  26.86293 24.22025  43.42826  26.952587
[4,]   1.88864 54.97618  12.50913 103.958836

I want the output, B, to be

B = 

     [,1] [,2] [,3] [,4]
[1,]    4    4    4    4
[2,]    3    2    3    1
[3,]    2    1    2    2
[4,]    1    3    1    3

I tried "apply(test,1,order)", but it did not work. Could anybody please
help? Thank you very much.

Wendy


--
View this message in context: http://r.789695.n4.nabble.com/get-the-sorted-index-of-elements-within-a-column-tp3896606p3896606.html
Sent from the R help mailing list archive at Nabble.com.
#
[,1] [,2] [,3] [,4]
[1,]    9   12    8   11
[2,]   12    7   11    8
[3,]   12    7    8    8
[4,]   11   11    4    8
[,1] [,2] [,3] [,4]
[1,]    9    7    4    8
[2,]   11    7    8    8
[3,]   12   11    8    8
[4,]   12   12   11   11
[,1] [,2] [,3] [,4]
[1,]    1    2    4    2
[2,]    4    3    1    3
[3,]    2    4    3    4
[4,]    3    1    2    1

HTH,
Dennis
On Tue, Oct 11, 2011 at 7:05 PM, Wendy <wendy2.qiao at gmail.com> wrote: