I am attempting to order data in a matrix using ranked data from a different matrix using R.
I have two matrices (X) and (rank). Each matrix has the same number of columns and rows. I would like to re-order the data in the columns from matrix (X) using the ranked data from the columns in matrix (rank). Column 1 in (X) should be ordered using the ranked data from column 1 in (rank).
I have searched the internet for a couple of days and have not come up with anything. I would appreciate any assistance.
Example:
Matrix (X)
Col1: A,B,C,D,E
Col2: A,B,C,D,E
Matrix (rank)
Col1: 2,4,5,3,1
Col2: 3,2,4,1,5
Goal Matrix (X.rank)
Col1: B,D,E,C,A
Col2: C,B,D,A,E
Thanks again.
If I understand you question correctly, you may want something like this:
I am not sure if you want to reorder each column of the matrix independently. To me, that does not make too much sense as we commonly keep matrices with rows per observation and columns for the variables—so you’d want to keep the rows together.
But you may have a different need, and what I have done here for the whole matrix can be done the same way column by column with individual assignments.