简体   繁体   中英

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. 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)) . 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))] .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM