[R] reordering of matrix rows to maximize the sum of the diagonal
Jonathan
jonsleepy at gmail.com
Fri Apr 23 22:10:29 CEST 2010
Hi r-help community,
This question isn't so much a syntax/coding one, but here goes:
Let's say I have matrix of arbitrary dimensions and I'd like to
reorder the rows in such a way that I could maximize the sum of the
entries along the diagonal.
For example, for this 3x3 matrix:
[,1] [,2] [,3]
[1,] 3 4 13
[2,] 9 1 2
[3,] 2 11 1
rearranging the rows to maximize the sum along the diagonal would
produce this matrix:
[,1] [,2] [,3]
[1,] 9 1 2
[2,] 2 11 1
[3,] 3 4 13
I've been experimenting with some scripts of my own, but I figured I'd
ask if one of you R-ninjas might know of an existing function (or
algorithm I could look up and then code) that can do this somewhat
efficiently (or even just correctly!).
Best,
Jonathan
More information about the R-help
mailing list