我使用以下数据创建图形
actors <- data.frame(name=c("Alice", "Bob", "Cecil",
"David","Esmeralda"),
age=c(48,33,45,34,21),
gender=c("F","M","F","M","F"))
relations <- data.frame(from= c("Bob", "Cecil", "Cecil", "David",
"David", "Esmeralda", "Alice"),
to= c("Alice", "Bob", "Alice", "Alice",
"Bob", "Alice", "Bob"),
same.dept= c( FALSE, FALSE, TRUE, FALSE,
FALSE, TRUE, FALSE),
friendship=c( 4, 5, 5, 2,
1, 1, 4),
advice= c( 4, 5, 5, 4,
2, 3, 4))
g <- graph.data.frame(relations, directed=TRUE, vertices=actors)
plot(g, layout=layout.kamada.kawai)
您可以看到顶点“Alice”和“Bob”在图形中具有双向。
我只是想看看哪个顶点有双向?我怎么能这样做?
非常感谢!
答案 0 :(得分:0)
您可以使用is.mutual()
来告诉您边缘是否在图表中具有相反的边缘:
is.mutual(g)
# [1] TRUE FALSE FALSE FALSE FALSE FALSE TRUE
cbind(get.edgelist(g), is.mutual(g))
# [,1] [,2] [,3]
# [1,] "Bob" "Alice" "TRUE"
# [2,] "Cecil" "Bob" "FALSE"
# [3,] "Cecil" "Alice" "FALSE"
# [4,] "David" "Alice" "FALSE"
# [5,] "David" "Bob" "FALSE"
# [6,] "Esmeralda" "Alice" "FALSE"
# [7,] "Alice" "Bob" "TRUE"