Hello Is there a way to sort each row of a matrix?
If,
a = { 1 2 7 4, 1 5 3 8 };
is a matrix with 2 rows and 4 columns, I want to get a matrix that is sorted on its each row separately i.e. I want to get the matrix
b = { 1 2 4 7, 1 3 5 8};
Is there any built in function to do that?
Thanks
Annesha
1 Answer
0
There is not built-in function to do that, but you could do this:
a = { 1 2 7 4, 1 5 3 8 }; b = sortAllR(a); proc (1) = sortAllR(a); local i; for i(1, rows(a), 1); a[i,.] = sortr(a[i,.], 1); endfor; retp(a); endp;
Your Answer
1 Answer
0
There is not built-in function to do that, but you could do this:
a = { 1 2 7 4, 1 5 3 8 }; b = sortAllR(a); proc (1) = sortAllR(a); local i; for i(1, rows(a), 1); a[i,.] = sortr(a[i,.], 1); endfor; retp(a); endp;