[R] Package corpcor: Putting symmetric matrix entries in vector
Steven Yen
syen04 at gmail.com
Sat Jan 31 00:03:45 CET 2015
Dear
I use sm2vec from package corpcor to puts the lower triagonal entries
of a symmetric matrix (matrix A) into a vector. However, sm2vec goes
downward (columnwise, vector B), but I would like it to go across
(rowwise). So I define a vector to re-map the vector (vector C). This
works. But is there a short-cut (simpler way)? Thank you.
> A<-cor(e); A
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1.00000000 0.5240809 0.47996616 0.11200672 -0.1751103 -0.09276455
[2,] 0.52408090 1.0000000 0.54135982 -0.15985028 -0.2627738 -0.14184545
[3,] 0.47996616 0.5413598 1.00000000 -0.06823105 -0.2046897 -0.23815967
[4,] 0.11200672 -0.1598503 -0.06823105 1.00000000 0.2211311 0.08977677
[5,] -0.17511026 -0.2627738 -0.20468966 0.22113112 1.0000000 0.23567235
[6,] -0.09276455 -0.1418455 -0.23815967 0.08977677 0.2356724 1.00000000
> B<-sm2vec(A); B
[1] 0.52408090 0.47996616 0.11200672 -0.17511026 -0.09276455
[6] 0.54135982 -0.15985028 -0.26277383 -0.14184545 -0.06823105
[11] -0.20468966 -0.23815967 0.22113112 0.08977677 0.23567235
> jj<-c(1,2,6,3,7,10,4,8,11,13,5,9,12,14,15)
> C<-B[jj]; C
[1] 0.52408090 0.47996616 0.54135982 0.11200672 -0.15985028
[6] -0.06823105 -0.17511026 -0.26277383 -0.20468966 0.22113112
[11] -0.09276455 -0.14184545 -0.23815967 0.08977677 0.23567235
More information about the R-help
mailing list