title: Counting edges in a graph by the attribute of nodes they connect
body: <p>Sorry for the vague question, I'm having difficulties in specifying exactly what I need. I hope the example will make it clearer. </p>
  
  <p>I have a network with various node attributes (like country affiliation, etc.). I am interested in how many of the nodes from a country are connected to the <em>same</em> or a <em>different</em> country. </p>
  
  <p>So, in the example network:</p>
  
  <pre><code>require(igraph)
  
  zach &lt;- graph("Zachary") # the Zachary carate club
  
  V(zach)$new_var &lt;- sample(c('tomato', 'gold', 'steelblue'), gorder(zach), replace = TRUE)
  
  plot(zach, vertex.size=10, vertex.label=NA, vertex.color = V(zach)$new_var)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ZXXjJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZXXjJ.png" alt="Example network with some attributes"></a></p>
  
  <p>I am interested here in, for example, how many <em>blue</em> nodes are connected to <em>blue</em>, to <em>red</em>, etc.</p>