[R] convert a vector to a symmetric matrix with all 0 on the diagonal
ruipbarradas at sapo.pt
Sun Jan 12 23:27:12 CET 2014
You should address your questions to R-Help, the odds of getting more
and better answers are greater.
As for your question, the trick is to use function ?lower.tri. (There's
also an upper.tri) Something like the following.
x <- 1:6
m <- matrix(0, nrow = 4, ncol = 4)
m[lower.tri(m)] <- x
res <- m + t(m)
Hope this helps,
Em 12-01-2014 21:21, yolande.tra at gmail.com escreveu:
> Hi Rui,
> You might not remember me but you have been very helpful in the past wit questions related to R. I saw one of your reply about creating a lower triangular matrix from a vector.
> I have a column in a data frame that I want to convert to a symmetric matrix with all 0 on the diagonal.
> Could you help?
> I appreciate.
> Sent from http://r.789695.n4.nabble.com
More information about the R-help