igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Calculating shortest path length among multiple graphs


From: 张伦
Subject: [igraph] Calculating shortest path length among multiple graphs
Date: Mon, 22 Dec 2014 13:35:36 +0800

Hi, 
I have an edgelist network data (undirected) with multiple graphs like this. For each graph (i.e., denoted by doc.id), I want to calculate the shortest path length (SPL) between the nodes. By using the code attached below, I can only calculate the SPL for only 1 graph at a time. How can I handle the multiple networks in R? 
Thanks for the help. 
Lun 
graph = data.frame(V1=c("A","A","B","B","C","D"), V2=c("C","D","F","A","A","Z"),      
doc.id=c("1","2","2","3","3","3"))
el=as.matrix(graph)
el[,1]=as.character(el[,1])
el[,2]=as.character(el[,2])
graph=graph.edgelist(el[,1:2],directed=FALSE) 
sp <- shortest.paths(graph, v=V(graph), to=V(graph),
  mode = c("all"),
  weights = NULL, algorithm = c("dijkstra"))
sp <-graph.adjacency(sp, mode=c( "undirected"), weighted=T)
sp <- cbind( get.edgelist(sp) , round( E(sp)$weight, 3 ))
sp

reply via email to

[Prev in Thread] Current Thread [Next in Thread]