title: How to speed of my R code when I use igraph?
body: <p>When I am running the following code it takes like forever to be run. Any idea how to speed up the code? Like changing the layout of matrix or hashing or ... ??</p>
  
  <p>I am aiming to create an edge-node triangle adjancey matrix at the very end and use it for co-clustering.</p>
  
  <pre><code>library(igraph)
  set.seed(1)
  g &lt;- erdos.renyi.game(100, .6)
  #print(g)
  plot(g)
  ij &lt;- get.edgelist(g)
  print(ij)
  library(Matrix)
  m &lt;- sparseMatrix(
    i = rep(seq(nrow(ij)), each=2),
    j = as.vector(t(ij)),
    x = 1
  )
  print(m)
  # Maximal cliques of size at least 3
  cl &lt;- maximal.cliques(g)
  print(cl)
  cl &lt;- cl[ sapply(cl, length) &gt; 2 ]
  print(cl)
  # Function to test if an edge is part of a triangle
  triangle &lt;- function(e) {
    any( sapply( cl, function(u) all( e %in% u ) ) )
  }
  print(triangle)
  # Only keep those edges
  kl &lt;- ij[ apply(ij, 1, triangle), ]
  print(kl)
  # Same code as before
  m &lt;- sparseMatrix(
    i = rep(seq(nrow(kl)), each=2),
    j = as.vector(t(kl)),
    x = 1
  )
  print(m)
  </code></pre>
  
  <p>This is literally where the code is stuck:
  <img src="https://i.stack.imgur.com/v5LBd.png" alt="enter image description here"></p>