Now I just need the resulting matrix:
2 8 9
4 6 7
1 3 5




On Mar 13, 2009, at 1:26 PM, Wacek Kusnierczyk wrote:

Kevski wrote:
Oh, this seemed so simple (and I'm sure the answer will be, as usual, so thanks in advance for enlightening me). I need to sort each row of a matrix
independent of the others. For example,


   apply(matrix, 1, sort)




Actually this give the transpose of what was requested, since the results from apply come back as column vectors. Try a slight refinement:
> outm <- t(apply(test,1,sort))
> outm
     [,1] [,2] [,3]
[1,]    2    8    9
[2,]    4    6    7
[3,]    1    3    5

--
David Winsemius

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to