title: sampling subgraphs from different sizes using igraph
body: <p>I have an igraph object <code>mygraph</code> with ~10,000 nodes and ~145,000 edges, and I need to create a number of subgraphs from this graph but with different sizes.
  What I need is to create subgraphs from a determined size (from 5 nodes to 500 nodes) where all the nodes are connected in each subgraph. I need to create ~1,000 subgraphs for each size (i.e, 1000 subgraphs for size5, 1000 for size 6, and so on), and then calculate some values for each graph according to different node attributes.
  I have some code but it takes a long time to do all the calculations. I thought in using the <code>graphlets</code> function in order to get the different sizes but every time I run it on my computer it crash due to memory issues. </p>
  
  <p>Here is the code I am using:</p>
  
  <p>First step was to create a function to create the subgraphs of different sizes and do the calculations needed.</p>
  
  <pre><code>random_network&lt;-function(size,G){
       score_fun&lt;-function(g){                                                        
            subsum &lt;- sum(V(g)$weight*V(g)$RWRNodeweight)/sqrt(sum(V(g)$RWRNodeweight^2))
             subsum
             } 
  
        genes.idx &lt;- V(G)$name
        perm &lt;- c()
        while(length(perm)&lt;1000){
             seed&lt;-sample(genes.idx,1) 
             while( length(seed)&lt;size ){
                  tmp.neigh &lt;- V(G)[unlist(neighborhood(G,1,seed))]$name
                  tmp.neigh &lt;- setdiff(tmp.neigh, seed)
                  if( length(tmp.neigh)&gt;0 )  
                  seed&lt;-c(seed,sample(tmp.neigh,1)) else break 
              }
        if( length(seed)==size )
        perm &lt;- c(perm,score_fun(induced.subgraph(G,seed)))
        } 
        perm
       } 
  </code></pre>
  
  <p>Second step was to apply the function to the actual graph</p>
  
  <pre><code> ### generate some example data
   library(igraph)
   my_graph &lt;- erdos.renyi.game(10000, 0.0003)
   V(my_graph)$name &lt;- 1:vcount(my_graph)
   V(my_graph)$weight &lt;- rnorm(10000)
   V(my_graph)$RWRNodeweight &lt;- runif(10000, min=0, max=0.05)
  
   ### Run the code to get the subgraphs from different size and do calculations based on nodes
   genesets.length&lt;- seq(5:500)
   genesets.length.null.dis &lt;- list()
   for(k in 5:max(genesets.length){ 
       genesets.length.null.dis[[as.character(k)]] &lt;- random_network(size=k,G=my_graph)
    }
  </code></pre>