[英]Find name of node associated with maximum degree in igraph data frame
I am using the igraph package to find degree of each node (the built in degree(g)
function) and it returns a numeric vector. 我使用igraph包来查找每个节点的
degree(g)
内置degree(g)
函数)并返回一个数字向量。 How can I tell which node has the maximum degree (not the value but the node name)? 如何判断哪个节点具有最大程度(不是值而是节点名称)?
If you have a igraph data frame G
, then you can create a TRUE/FALSE vector with degree(G)==max(degree(G))
. 如果你有一个igraph数据框
G
,那么你可以创建一个degree(G)==max(degree(G))
的TRUE / FALSE向量。 You can then use that to find the name of the node(s) that meet that criteria - V(G)$name[degree(G)==max(degree(G))]
. 然后,您可以使用它来查找符合该条件的节点的名称 -
V(G)$name[degree(G)==max(degree(G))]
。
I created a small example to illustrate: 我创建了一个小例子来说明:
library(igraph)
df = data.frame(node1=c("Bob", "Jim", "Dave", "Dave"),
node2=c("Jane", "John", "Sally", "Al"))
G = graph.data.frame(df)
V(G)$name[degree(G)==max(degree(G))]
[1] "Dave"
Example data 示例数据
dat<-sample(0:100,100,rep=FALSE)
maximum<-dat[order(dat,decreasing = TRUE)
Verify 校验
maximum
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.