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
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
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
3 matches
Mail list logo