From a matrix of distances to a matrix of adjacency
<p>I have a matrix of distances 1024x1024 with all the couple of distances between all the terms. I want to define a graph starting from that. So I defined a minimum spanning tree and I computed the matrix of adjacency on that.</p>

<p>My matrix of distances is <code>distMat</code>.</p>

<pre><code>matrix_of_distances &lt;- as.matrix(distMat)
myGraph &lt;- graph.adjacency(matrix_of_distances, weighted=TRUE)
</code></pre>

<p>My graph is a graph with all the possible arcs (because the distances between all the couple of terms are a finite value). I need another graph, sparser:</p>

<pre><code>mst &lt;- as.undirected(minimum.spanning.tree(myGraph))
</code></pre>

<p>From that sparse graph I can compute the matrix of adjacency with:</p>

<pre><code>adjacency &lt;- as_adjacency_matrix(mst, type = c("both", "upper", "lower"), attr = NULL, edges = FALSE, names = TRUE, sparse =igraph_opt("sparsematrices"))
</code></pre>

<p>Now I want to create the matrix adjacency differently, passing another minimum spanning tree object. Suppose I have created another spanning tree:</p>

<pre><code>spt &lt;- spantree(matrix_of_distances)
</code></pre>

<p>If I do:</p>

<pre><code>adjacency &lt;- as_adjacency_matrix(spt, type = c("both", "upper", "lower"), attr = NULL, edges = FALSE, names = TRUE, sparse =igraph_opt("sparsematrices"))
</code></pre>

<p>I get the error:</p>

<blockquote>
  <p>Error in as_adjacency_matrix(spt, type = c("both", "upper", "lower"), 
  :    Not a graph object</p>
</blockquote>

<p>Again, I'm trying to generate a matrix of adjacency from a minimum spanning tree. How can I solve that? </p>