## Try this,
x <- matrix(rnorm(80), ncol=8, nrow=10)
out <- cbind( c(x), c(row(x)), c(col(x)))
out[order(out[,1]),]
### Simon Byers, AT&T Labs.
From: Joseph S. Verducci <jsv@stat.ohio-state.edu>
Is
matrix(rank(a),nrow(a),ncol(a))
what you want?
Example:
> a
[,1] [,2] [,3]
[1,] 27 24 29
[2,] 21 22 28
[3,] 23 26 25
> sort(a)
[1] 21 22 23 24 25 26 27 28 29
> matrix(rank(a),nrow(a),ncol(a))
[,1] [,2] [,3]
[1,] 7 4 9
[2,] 1 2 8
[3,] 3 6 5
From: Jim Hughes <hughes@diamond.cfas.washington.edu>
Kim -
Does this do what you want?
ord <- order(mat)
mat[ord] # orders the elements of the matrix mat
cbind(row(mat)[ord],col(mat)[ord]) # gives the row, col index of each
# ordered element in the original matrix
Jim
Kim Elmore, [N5OP, PP ASMEL/Glider 2232456]
"All of Meteorology is divided into three parts: Yes, No and Maybe. The
greatest of these is Maybe." -- The original Latin appears to be garbled.
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|