Re: [R] getting column names of row-by-row sorted matrix

2010-09-01 Thread David Winsemius
On Sep 1, 2010, at 11:34 AM, David Winsemius wrote: snipped > t( apply(a, 1, function(x) colnames(a)[order(x)]) ) [,1] [,2] [,3] [,4] [1,] "A" "C" "B" "D" [2,] "A" "C" "B" "D" [3,] "D" "B" "C" "A" [4,] "B" "A" "C" "D" [5,] "C" "D" "B" "A" (apply returns a transposed version

Re: [R] getting column names of row-by-row sorted matrix

2010-09-01 Thread David Winsemius
On Sep 1, 2010, at 11:18 AM, wrote: Hi folks, I want to sort a matrix row-by-row and create a new matrix that contains the corresponding colnames of the original matrix. E.g. set.seed(123) a <- matrix(rnorm(20), ncol=4); colnames(a) <- c("A","B","C","D") a A B

[R] getting column names of row-by-row sorted matrix

2010-09-01 Thread Murali.Menon
Hi folks, I want to sort a matrix row-by-row and create a new matrix that contains the corresponding colnames of the original matrix. E.g. > set.seed(123) > a <- matrix(rnorm(20), ncol=4); colnames(a) <- c("A","B","C","D") > a A B C D [1,] -0.56047565