title: obtaining upper-triangular matrix from sparse-matrix
body: <p>I have a symmetric but sparse matrix of 0's and 1's representing whether or not there is an edge or link between two objects  --- an adjacency matrix. I am attempting to work with the command PAM in the cluster package in R, which requires either a dissimilarity-matrix (and in particular the upper-triangular of this matrix) or a distance. </p>
  
  <p>Below find a representative matrix (although my matrix has many more edges and nodes and unlike this matrix is in fact sparse).</p>
  
  <pre><code>0  1 0 0
  1  0 0 0
  0  0 0 1
  0  0 1 0
  </code></pre>
  
  <p>I require an upper-triangular version of my matrix which means that I need to obtain this matrix. my problem is that is that my matrix at least is singular so Matrix commands such as a regular LU decomposition or Choleski decomposition do not work with it.</p>
  
  <p>here is the error message that I got when I tried my 64 * 64 sparse matrix:</p>
  
  <pre><code>Warning message:
  In .local(x, ...) :
  Exact singularity detected during LU decomposition: U[i,i]=0, i=20.
  </code></pre>
  
  <p>I have read over several posts here on sparse matrices including "<a href="https://stackoverflow.com/questions/12379426/large-sparse-matrix-to-triangular-matrix-r">Large Sparse Matrix to Triangular Matrix R</a>"</p>
  
  <p>but they do not seem to do exactly what I want.</p>
  
  <p>I am wondering if anyone has advice on what R commands I should try to obtain my desired matrix. If necessary, I can attempt to program up my own function but I would rather not do so.</p>