Juliet Ndukum
2010-Sep-15 20:56 UTC
[R] Moving non-zero matrix entries to different locations on the matrix
I have a matrix:
C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12
R1 0 0 0 0 0 5 0 0 0 0 0 0
R2 0 0 0 0 0 3 0 0 0 0 0 0
R3 0 0 0 0 0 0 4 0 0 0 0 0
R4 0 0 0 0 0 0 2 0 0 0 0 0
R5 1 0 0 0 0 0 0 0 0 0 0 0
R6 8 0 0 0 0 0 0 0 0 0 0 0
R7 0 15 6 0 3 0 0 0 0 0 0 0
R8 0 9 7 18 17 0 0 0 0 0 0 44
R9 0 0 0 23 0 0 0 0 0 0 0 52
R10 0 0 0 0 0 0 0 0 0 0 19 0
where most of the entries are zeros. I wish to move some of the non -zero
entries to locations where there are not as many non-zero entries giving a
matrix like the one below:
C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12
R1 0 0 0 0 0 0 0 0 0 0 0 0
R2 0 0 0 0 0 0 0 0 0 0 0 0
R3 0 0 0 0 0 0 0 0 0 0 0 0
R4 0 0 0 0 0 0 0 0 0 0 0 0
R5 0 0 0 0 0 0 0 0 0 0 0 0
R6 0 0 0 0 0 0 0 0 0 0 0 0
R7 1 15 6 18 3 5 4 0 0 0 0 44
R8 8 9 7 23 17 3 2 0 0 0 0 52
R9 0 0 0 0 0 0 0 0 0 0 0 0
R10 0 0 0 0 0 0 0 0 0 0 19 0
R7 and R8 had more non-zero entries than all the other rows so, the non-zero
entries had to be moved to R7 and R8.
Can any one write a simple function that can implement this idea.
Thanks in advance for your help,
JN
[[alternative HTML version deleted]]