On 20/01/2008 10:50 AM, threshold wrote: > Hi, I want to sort my matrix according to (any) selected column. For example > given matrix: >> x > [,1] [,2] [,3] > [1,] 3 4 7 > [2,] 2 5 8 > [3,] 1 6 9 > > I want to sort the first column in ascending order and make the other > columns follow the 'new order' like: > >> x1 > [,1] [,2] [,3] > [1,] 1 6 9 > [2,] 2 5 8 > [3,] 3 4 7 > > thank in advance for help.
See ?order. o <- order(x[,1]) x1 <- x[o,] Duncan Murdoch ______________________________________________ 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.