Reputation: 417
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)?
Upvotes: 3
Views: 7948
Reputation: 3121
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"
Upvotes: 10
Reputation: 1932
Example data
dat<-sample(0:100,100,rep=FALSE)
maximum<-dat[order(dat,decreasing = TRUE)
Verify
maximum
Upvotes: 2