title: R: Convert upper triangular part of a matrix to symmetric matrix
body: <p>I have the upper triangular part of matrix in R (without diagonal) and want to generate a symmetric matrix from the upper triangular part (with 1 on the diagonal but that can be adjusted later). I usually do that like this:</p>
  
  <pre><code>res.upper &lt;- rnorm(4950)
  res &lt;- matrix(0, 100, 100)
  res[upper.tri(res)] &lt;- res.upper
  rm(res.upper)
  diag(res) &lt;- 1
  res[lower.tri(res)]  &lt;- t(res)[lower.tri(res)]
  </code></pre>
  
  <p>This works fine but now I want to work with very large matrices. Thus, I would want to avoid having to store res.upper and res (filled with 0) at the same time. Is there any way I can directly convert res.upper to a symmetric matrix without having to initialize the matrix res first?</p>