Thank you. Yes, I did look at the help but could not get my expressions to work.
You used a data.frame with thematrix values I gave. Your solution also works
when dealing with a matrix (this my be obvious to seasoned R users, but was no
to me).
> x<-matrix(c(57,91,31,61,16,84,3,99,85,47,21,6,57,91,31,61,16,84,3,99),
> ncol=5, byrow=TRUE)
> #order by row
> order(x[,1])
[1] 3 1 4 2
> x[order(x[,1]),]
[,1] [,2] [,3] [,4] [,5]
[1,] 21 6 57 91 31
[2,] 57 91 31 61 16
[3,] 61 16 84 3 99
[4,] 84 3 99 85 47
> #order by column
> order(x[1,])
[1] 5 3 1 4 2
> x[,order(x[1,])]
[,1] [,2] [,3] [,4] [,5]
[1,] 16 31 57 61 91
[2,] 47 99 84 85 3
[3,] 31 57 21 91 6
[4,] 99 84 61 3 16
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.