[R] Constructing a symmetric matrix using library(corpcor)
Steven Yen
syen04 at gmail.com
Wed Feb 17 06:07:55 CET 2016
Hello
I am constructing a symmetric matrix with library "corpcor". In the
codes below, I am able to construct a symmetric matrix of order 3 and
4. However, the 5 x 5 matrix does not seem right? Help?
Thanks.
> library(corpcor)> r <- 1:3> rr <- vec2sm(r, diag = F)> rr <- rr[upper.tri(rr)]> r <- vec2sm(rr, diag = F); diag(r) <- 1> r [,1] [,2] [,3]
[1,] 1 1 2
[2,] 1 1 3
[3,] 2 3 1> > r <- 1:6> rr <- vec2sm(r, diag = F)> rr <-
rr[upper.tri(rr)]> r <- vec2sm(rr, diag = F); diag(r) <- 1> r
[,1] [,2] [,3] [,4]
[1,] 1 1 2 4
[2,] 1 1 3 5
[3,] 2 3 1 6
[4,] 4 5 6 1> > r <- 1:10> rr <- vec2sm(r, diag = F)> rr
<- rr[upper.tri(rr)]> r <- vec2sm(rr, diag = F); diag(r) <- 1> r
[,1] [,2] [,3] [,4] [,5]
[1,] 1 1 2 5 3
[2,] 1 1 6 8 4
[3,] 2 6 1 7 9
[4,] 5 8 7 1 10
[5,] 3 4 9 10 1
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list