给定一个顶点v1,我怎样才能得到边(v1,v2)具有最大权重的顶点v2?
我解决这个问题的方法是这样的:
library(igraph)
maxEdge = max(E(g)[from(id)]$weight
which(E(g)$weight==maxEdge))
但我不知道如何获取顶点 ID。有任何想法吗?
最小示例数据
library(igraph)
g1 <- graph.full(5)
V(g1)$name <- 1:5
g2 <- graph.full(5)
V(g2)$name <- 6:10
g3 <- graph.ring(5)
V(g3)$name <- 11:15
g <- g1 + g2 + g3 + edge('1', '6') + edge('1', '11')
V(g)$name <- letters[1:vcount(g)]
# Random data
set.seed(ecount(g))
E(g)$weight <- runif(ecount(g))
maxEdge = max(E(g)[from(1)]$weight)
idEdge = which(E(g)$weight==maxEdge)
我的方法得到边缘 id (idEdge)。但是,想要获取顶点 ID!
例如:
V(g)
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o"
E(g)[from("a")] -> $weight
[1] b -- a -> 0.97175023
[2] c -- a -> 0.08375751
[3] d -- a -> 0.87386992
[4] e -- a -> 0.32923136
[26] f -- a -> 0.10740653
[27] k -- a -> 0.56277556
考虑到上面的例子,我需要的是一个必须返回“b”或“2”的函数。