title: R: Collect igraph nodes adjacent to selected nodes in a list
body: <p>Define the toy graph as:</p>
  
  <pre><code>&gt; library(igraph)
  &gt; g = graph( c("John", "Jim",
                 "Jim", "Jill", 
                 "Jill", "John",
                 "Jim", "Bob",
                 "Bob", "Alice", 
                 "Alice", "Jill"),
              directed=FALSE)
  </code></pre>
  
  <p>Select 2 nodes randomly as:</p>
  
  <pre><code>&gt; select = V(g)[sample(1:5,2)]
  &gt; select
  + 2/5 vertices, named, from b165a23:
  [1] John Jim
  </code></pre>
  
  <p>Determine nodes immediately adjacent to the 2 above selected nodes in graph:</p>
  
  <pre><code>&gt; adj = adjacent_vertices(g,select,mode="all")
  &gt; adj
  $John
  + 2/5 vertices, named, from b165a23:
  [1] Jim  Jill
  $Jim
  + 3/5 vertices, named, from b165a23:
  [1] John Jill Bob 
  </code></pre>
  
  <p>What I get is a list <code>adj</code> made of 2 lists: <code>adj$John</code> and <code>adj$Jim</code>. <BR> 
  What I want is to collect all nodes adjacent to John and Jim, that is:<BR>
  Jim, Jill, John, Jill and Bob<BR>
  then put them in a single list. Jill is repeated intentionally because I am actually interested in counting edge stubs.</p>
  
  <p>I did try various ways,e.g.:</p>
  
  <pre><code>sel_list=adj$John
  for  (ii = 2:(length(adj)) {
    sel_list = append(sel_list,adj[[ii]]) 
  }
  </code></pre>
  
  <p>or </p>
  
  <pre><code>sel_list = c()
  for  (ii = 1:(length(adj)) {
    sel_list = c(sel_list,adj[[ii]]) 
  }
  </code></pre>
  
  <p>The above does give me a list of vertices, but only captures the first component of the lists <code>adj[[ii]]</code>. For large problems, I need a way to collect all adjacent vertices without resorting to yet another expensive <code>for</code> loops to capture all elements of <code>adj[[ii]]</code>, such as the ugly hack:</p>
  
  <pre><code>sel_list = c()
  for  (ii = 1:(length(adj)) {
    int_list=c()
    for (kk in 1:length(adj[[ii]]) {
      int_list=c(int_list,adj[[ii]][kk])
    }
    sel_list = c(sel_list,int_list) 
  }
  </code></pre>
  
  <p>which, for a reason I don't understand, does not capture all nodes in <code>adj[[ii]]</code> as I expected.</p>
  
  <p>What is the best way to go about selecting all adjacent nodes to a set of other nodes and put them in a simple list ?</p>