Reputation: 203
I have a graph:
g <- make_empty_graph (2) %>%
set_vertex_attr("a", value = 1) %>%
add_vertices(2, color = 2, "a" = 2) %>%
add_vertices(2, color = 4, "a" = 3) %>%
add_edges(c(1, 2, 2, 1, 1, 5, 5, 1, 1, 4, 4, 1))
plot(g)
Is there a way to find out how many nodes with a value of 2 for the attribute "a" are connected to the node "1"?
Upvotes: 0
Views: 814
Reputation: 37641
You can get the neighbors of node 1 using neighbors
and then test for which ones have "a"=2.
NeighborList = neighbors(g, 1)
NeighborList[NeighborList$a == 2]
+ 1/6 vertex, from 3502fa5:
[1] 4
Upvotes: 1