Great! Thanks. Thanks to all who tried to help.
as.vector(r[upper.tri(r)]) does it:
> e<-as.matrix(cbind(u1,u2,u3,v1,v2,v3))
> r<-cor(e); r
[,1] [,2][,3][,4] [,5][,6]
[1,] 1. 0.5240809 0.47996616 0.11200672 -0.1751103 -0.09276455
[2,] 0
If you have a symmetric matrix, you can work with the upper triangle
instead of the lower one, and you get what you want by simply using
as.vector(A[upper.tri(A)])
Example:
> a = matrix(rnorm(16), 4, 4)
> A = a + t(a)
> A
[,1] [,2] [,3][,4]
[1,] 0.3341294 0.5460334
On Jan 30, 2015, at 3:03 PM, Steven Yen wrote:
> 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 ve
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
4 matches
Mail list logo