[R] generating symmetric matrices
Cleber Borges
klebyn at yahoo.com.br
Mon Jul 30 20:46:04 CEST 2007
hello
try
?upper.tri
############# example
p <- 6
Rmat <- diag(p)
dat.cor <- rnorm(p*(p-1)/2)
Rmat[upper.tri(Rmat)]<- dat.cor
Rmat[lower.tri(Rmat)]<- dat.cor
Cleber Borges
> 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:
>
> p <- 6
> Rmat <- diag(p)
> dat.cor <- rnorm(p*(p-1)/2)
> Rmat[outer(1:p, 1:p, "<")] <- Rmat[outer(1:p, 1:p, ">")] <- dat.cor
>
> However, the problem is that the matrix is filled by column and so the resulting matrix is not symmetric.
>
> I'd be grateful for any adive and/or solutions.
>
> Gregory
>
>
_______________________________________________________
Experimente já e veja as novidades.
More information about the R-help
mailing list