0

我使用以下数据创建图形,

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”在图形中具有双向性。

我只想看看哪些顶点是双向的?我怎样才能做到这一点?

非常感谢!

4

1 回答 1

0

您可以使用is.mutual()which 告诉您一条边在图中是否有相反的边:

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" 
于 2013-07-30T14:15:42.917 回答