我有一张图表:
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)
有没有办法找出属性“a”连接到节点“1”的值为2的节点数?
答案 0 :(得分:1)
您可以使用neighbors
获取节点1的邻居,然后测试哪些具有&#34; a&#34; = 2。
NeighborList = neighbors(g, 1)
NeighborList[NeighborList$a == 2]
+ 1/6 vertex, from 3502fa5:
[1] 4