[R] generating symmetric matrices
Ben Bolker
bolker at ufl.edu
Mon Jul 30 22:15:46 CEST 2007
Gregory Gentlemen <gregory_gentlemen <at> yahoo.ca> writes:
>
> Greetings,
>
> I have a seemingly simple task which I have not been able to solve today. I
want to construct a symmetric
> matrix of arbtriray size w/o using loops. The following I thought would do it:
>
[snip]
p <- 6
Rmat <- diag(p)
vals <- rnorm(p*(p-1)/2)
Rmat[lower.tri(Rmat)] <- vals
Rmat[upper.tri(Rmat)] <- t(Rmat)[upper.tri(Rmat)]
appears to work.
More information about the R-help
mailing list