Hang's Blog
Observations and thinkings about economy, society and life.
Pages
Wednesday, 12 November 2014
Convert Matrix into Symmetric in R
require(Matrix):
forceSymmetric(dat, uplo="U"))
Assign the lower triangular part to the upper triangular part:
dat[upper.tri(dat)] <- t(dat)[lower.tri(dat)]
micEcon package:
symMatrix(dat[upper.tri(dat, TRUE)], nrow=nrow(dat), byrow=TRUE)
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)