Entering edit mode
Gustavo Lacerda
▴
40
@gustavo-lacerda-3916
Last seen 10.4 years ago
hi,
I would like to easily query the weight (or label) of an edge given
its name.
e.g. suppose I have a graph 'g' whose nodes are labeled A1, A2, ...
I want to do something like: getEdge(g, "A1~A3")$weight
Any suggestions?
The best I can do at the moment is the code below, but I don't find it
very elegant that I need to do [[1]], and I don't like to reinvent the
wheel. Is there a standard function I can use?
Gustavo
parseTilde <- function(s) unlist(strsplit(s,"~"))
getEdgeWeight <- function(g, edgeName){
nodePair <- parseTilde(edgeName)
edgeData(g, from=nodePair[1], to=nodePair[2])[[1]]$weight
}