I'm new to R and igraph and I was wondering if anybody can help me with the following. I want to find the edge weight between two vertices in a graph. My graph structure is defined by the normal ego (node1), alter (node2) and the weight of the edge between them. I know that I can get the weight for each of the edges in the list of edges that originate from node number 5 using E(igraph_friendship) [ from(5) ]$weight And that I can find the weight for each of the edges in the list of edges that end onto node number 10 using E(igraph_friendship) [ to(10) ]$weight But what if I simply want to find the weight of the edge that simple connects just node 5 and node 10? Alternatively, if I can get the identifier of the edge that connects node 5 and 10 in the list of all edges, E(igraph_friendship), that would work too. Thanks a lot for your help, I've been looking around a lot for it and I really appreciate your help! -- View this message in context: http://r.789695.n4.nabble.com/help-finding-edge-connecting-two-nodes-tp4646688.html Sent from the R help mailing list archive at Nabble.com.
help finding edge connecting two nodes
4 messages · dhaval@mit.edu, Rui Barradas, Dhaval Adjodah +1 more
Hello, You should give a reproducible example showing us what you have tried, with an example dataset. Try the following. # A graph I've just drawn v <- c(1,2,1,3,1,4,2,5,2,4,3,5,3,6,5,7,5,8,5,10,6,8,6,10,7,8,7,9,8,9) g <- graph(v, directed = FALSE) plot(g, layout=layout.fruchterman.reingold) E(g)$weight <- 1:15 # This is what you want E(g)[5 %--% 10]$weight See the help for ?igraph::iterators Hope this helps, Rui Barradas Em 18-10-2012 23:05, dhaval at mit.edu escreveu:
I'm new to R and igraph and I was wondering if anybody can help me with the following. I want to find the edge weight between two vertices in a graph. My graph structure is defined by the normal ego (node1), alter (node2) and the weight of the edge between them. I know that I can get the weight for each of the edges in the list of edges that originate from node number 5 using E(igraph_friendship) [ from(5) ]$weight And that I can find the weight for each of the edges in the list of edges that end onto node number 10 using E(igraph_friendship) [ to(10) ]$weight But what if I simply want to find the weight of the edge that simple connects just node 5 and node 10? Alternatively, if I can get the identifier of the edge that connects node 5 and 10 in the list of all edges, E(igraph_friendship), that would work too. Thanks a lot for your help, I've been looking around a lot for it and I really appreciate your help! -- View this message in context: http://r.789695.n4.nabble.com/help-finding-edge-connecting-two-nodes-tp4646688.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121019/274f394c/attachment.pl>
On Fri, Oct 19, 2012 at 2:50 PM, Dhaval Adjodah <nuclearr.d at gmail.com> wrote:
[...]
Your way works best! Another way I found from stackoverflow (see the post at http://stackoverflow.com/questions/12964332/igraph-edge-between-two-vertices/12980550#12980550) was to convert the graph into an adjacency matrix and then use simple matrix indices .
Just make this clear. The example (repeated below) on the stackoverflow page does _not_ convert the graph into an adjacency matrix. The indexing only makes the graph look as if it was an adjacency matrix. But there is no conversion at all. Gabor ps. I would appreciate if you didn't cross-post your questions everywhere (R-help, igraph-help and stackoverflow, maybe other places as well). Please only post it on the platform you prefer first and then, if you don't get a good answer, try elsewhere. Thanks! library(igraph) g <- graph.ring(10) g[1,2] # [1] 1 E(g)$weight <- runif(ecount(g)) g[1,2] # [1] 0.8115639 [...]