title: igraph split graph into clusters
body: <p>I have some undirected graph:</p>
  
  <p><a href="https://i.stack.imgur.com/IOp3R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IOp3R.png" alt="enter image description here"></a></p>
  
  <p>with data:</p>
  
  <pre><code>get.data.frame(out)
     from   to  value sourceID targetID
  1    74   80 0.2829   255609   262854
  2    74   61 0.2880   255609   179585
  3    80 1085 0.2997   262854  3055482
  4  1045 1046 0.1842  2970629  2971615
  5  1046 1085 0.2963  2971615  3055482
  6  1046 1154 0.2714  2971615  3087803
  7  1085 1154 0.2577  3055482  3087803
  8  1085 1187 0.2850  3055482  3101131
  9  1085 1209 0.2850  3055482  3110186
  10 1154 1243 0.2577  3087803  3130848
  11 1154 1187 0.2305  3087803  3101131
  12 1154 1209 0.2305  3087803  3110186
  13 1154 1244 0.2577  3087803  3131379
  14 1243 1187 0.1488  3130848  3101131
  15 1243 1209 0.1488  3130848  3110186
  16 1243 1244 0.1215  3130848  3131379
  17 1243 1281 0.2997  3130848  3255811
  
  &gt; out
  IGRAPH UN-- 12 17 -- 
  + attr: name (v/c), color (v/n), value (e/n), sourceID (e/n), targetID (e/n)
  + edges (vertex names):
   [1] 74  --80   74  --61   80  --1085 1045--1046 1046--1085 1046--1154 1085--1154 1085--1187 1085--1209 1154--1243 1154--1187 1154--1209
  [13] 1154--1244 1243--1187 1243--1209 1243--1244 1243--1281
  </code></pre>
  
  <p>I am using two methods for community detection.</p>
  
  <p>Using <code>edge.betweenness.community</code> I can split communities by calculating edge betweenness:</p>
  
  <pre><code>wc &lt;- edge.betweenness.community(out, weights = E(out)$value, directed = FALSE, bridges=TRUE)
  plot(wc, out)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/vOqAe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vOqAe.png" alt="enter image description here"></a></p>
  
  <p>Using <code>cluster_optimal</code> I can split communities by maximising modularity:</p>
  
  <pre><code>co &lt;- cluster_optimal(out, weights = E(out)$value)
  plot(co, out)
  </code></pre>
  
  <p>Data for co:</p>
  
  <pre><code>&gt; co
  IGRAPH clustering optimal, groups: 3, mod: 0.27
  + groups:
    $`1`
    [1] "74" "80" "61"
  
    $`2`
    [1] "1045" "1046" "1085" "1154" "1187" "1209"
  
    $`3`
    [1] "1243" "1244" "1281"
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/x9KuA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x9KuA.png" alt="enter image description here"></a></p>
  
  <p>At this point, I want to split these graphs into individual communities. This is done by cutting those edges that are highlighted red.</p>
  
  <p>I can do this for <code>edge.betweenness.community</code> by returning those edges which are to be cut by doing:</p>
  
  <pre><code>wc$removed.edges
  [1]  3  6  5 17 14 11  8 15  7 12  1  2  4  9 10 13 16
  </code></pre>
  
  <p>I can then cut those edges:</p>
  
  <pre><code>g2&lt;-delete.edges(out, wc$removed.edges[seq(length=which.max(mods)-1)])
  plot(g2)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/b8cC5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b8cC5.png" alt="enter image description here"></a></p>
  
  <p>But if I try this for <code>cluster_optimal</code>:</p>
  
  <pre><code>co$removed.edges
  NULL    
  </code></pre>
  
  <p>It looks like <code>cluster_optimal</code> has no attribute <code>removed$edges</code></p>
  
  <p>I then looked in the documentation (<a href="http://igraph.org/r/doc/communities.html" rel="nofollow noreferrer">http://igraph.org/r/doc/communities.html</a>) and tried <code>cut_at</code> and <code>cutat</code>:</p>
  
  <pre><code>&gt; cutat(co, 3)
  Error in cutat(co, 3) : Not a hierarchical communitity structure
  &gt; cut_at(co, 3)
  Error in cut_at(co, 3) : Not a hierarchical communitity structure
  </code></pre>
  
  <p>This has not worked either, even though <code>co</code> should be a community object.</p>
  
  <p>How can I split my <code>cluster_optimal</code> graph into the individual communities like I did with <code>edge.betweenness.community</code>?</p>
  
  <hr>
  
  <p>Trying the suggestion posted, when i try to execute</p>
  
  <pre><code>crossing(co, out)
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>Error: Each element must be either an atomic vector or a data     frame
  .Problems: co, out.
  </code></pre>
  
  <hr>
  
  <pre><code>R version 3.4.0 (2017-04-21)
  Platform: x86_64-pc-linux-gnu (64-bit)
  Running under: Ubuntu 14.04.5 LTS
  
  Matrix products: default
  BLAS: /usr/lib/libblas/libblas.so.3.0
  LAPACK: /usr/lib/lapack/liblapack.so.3.0
  
  locale:
   [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
   [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
  [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
   [1] plotly_4.7.0        ggplot2_2.2.1       tidyr_0.6.2         dtplyr_0.0.2        data.table_1.10.4   DT_0.2             
   [7] reshape2_1.4.2      igraph_1.0.1        dplyr_0.5.0         htmlwidgets_0.8     networkD3_0.4       htmltools_0.3.6    
  [13] formattable_0.2.0.1
  
  loaded via a namespace (and not attached):
   [1] Rcpp_0.12.10      compiler_3.4.0    plyr_1.8.4        tools_3.4.0       digest_0.6.12     jsonlite_1.4      evaluate_0.10    
   [8] tibble_1.3.0      gtable_0.2.0      viridisLite_0.2.0 lattice_0.20-35   Matrix_1.2-10     DBI_0.6-1         stringr_1.2.0    
  [15] httr_1.2.1        knitr_1.15.1      rprojroot_1.2     grid_3.4.0        R6_2.2.0          rmarkdown_1.5     purrr_0.2.2      
  [22] magrittr_1.5      backports_1.0.5   scales_0.4.1      assertthat_0.2.0  colorspace_1.3-2  stringi_1.1.5     lazyeval_0.2.0   
  [29] munsell_0.4.3 
  </code></pre>