**From:** Andy Bunn (*abunn@montana.edu*)

**Date:** Tue 13 May 2003 - 14:18:18 EST

**Next message:**Tony Plate: "Re: [R] Sorting a matrix in an odd way"**Previous message:**Ted Harding: "RE: [R] FW: S+ Script Files for R???"**Next in thread:**Tony Plate: "Re: [R] Sorting a matrix in an odd way"**Reply:**Tony Plate: "Re: [R] Sorting a matrix in an odd way"**Maybe reply:**Adaikalavan Ramasamy: "RE: [R] Sorting a matrix in an odd way"**Reply:**Kenneth Cabrera: "Re: [R] Sorting a matrix in an odd way"

Message-id: <000201c31906$c1ab8f10$d4a00ecf@simATE>

Hi, I have a matrix not unlike this:

foo <- matrix(,5,5)

foo[5,1] <- 1

foo[1:3,2] <- 1

foo[3:4,3] <- 1

foo[4:5,4] <- 1

foo[2:4,5] <- 1

foo

[,1] [,2] [,3] [,4] [,5]

[1,] NA 1 NA NA NA

[2,] NA 1 NA NA 1

[3,] NA 1 1 NA 1

[4,] NA NA 1 1 1

[5,] 1 NA NA 1 NA

I want to get a vector that is the column numbers as sorted by the first

non-NA value.

Like this:

2,5,3,4,1

I have been able to do this by adding an index and looping the matrix by

column. Can anybody think of a cleverer way to do this?

Thanks, as always, in advance.

Andy

______________________________________________

R-help@stat.math.ethz.ch mailing list

https://www.stat.math.ethz.ch/mailman/listinfo/r-help

**Next message:**Tony Plate: "Re: [R] Sorting a matrix in an odd way"**Previous message:**Ted Harding: "RE: [R] FW: S+ Script Files for R???"**Next in thread:**Tony Plate: "Re: [R] Sorting a matrix in an odd way"**Reply:**Tony Plate: "Re: [R] Sorting a matrix in an odd way"**Maybe reply:**Adaikalavan Ramasamy: "RE: [R] Sorting a matrix in an odd way"**Reply:**Kenneth Cabrera: "Re: [R] Sorting a matrix in an odd way"

*
This archive was generated by hypermail 2.1.3
: Tue 01 Jul 2003 - 09:11:49 EST
*