title: From asymmetric matrix (or dataframe) into a symmetric square matrix with R
body: <p>Given this data.frame: 'sample', which represents pairwise wins and losses among species:</p>
  
  <pre><code>     sp1&lt;-c(0,1,0)
       sp3&lt;-c(1,2,2)
       sp5&lt;-c(3,1,0)
       sample&lt;-as.data.frame(cbind(sp1,sp3,sp5))
       rownames(sample)&lt;-c("sp1","sp6","sp8")
  </code></pre>
  
  <p>which should look like this:</p>
  
  <pre><code>    sp1 sp3 sp5
  sp1   0   1   3
  sp6   1   2   1
  sp8   0   2   0
  </code></pre>
  
  <p>How do I modify 'sample' so that it has the same column names as rownames, and viceversa, and fill in the added columns or rows with zeros for the dataframe to be symmetric and look like shown below? (I prefer dataframe because I am afraid I am not good with matrices):</p>
  
  <pre><code>    sp1 sp3 sp5 sp6 sp8
  sp1   0   1   3   0   0
  sp3   0   0   0   0   0
  sp5   0   0   0   0   0
  sp6   1   2   1   0   0
  sp8   0   1   0   0   0
  </code></pre>
  
  <p>The real data has around 150 rows and columns, so I don't really want
   to do it manually with excel. This format is required to apply some other function concerning competitive species interaction outcomes (columns:wins, rows: losses).</p>