library(igraph)
data <-
"AS3 AS6 AS10 AS1
AS56 AS23 AS36 AS1
AS123 AS568 AS2 AS45 AS36 AS1
AS79 AS1"
paths <- readLines(textConnection(data))
edges <- lapply(strsplit(paths, " "), function(x) {
if (length(x)==2) {
x
} else {
c(x[1], rep(x[2:(length(x)-1)], each=2), x[length(x)])
}
})
G <- graph.edgelist(matrix(unlist(edges), ncol=2,
byrow=TRUE))
str(G)
# IGRAPH DN-- 12 12 --
# + attr: name (v/c)
# + edges (vertex names):
# [1] AS3 ->AS6 AS6 ->AS10 AS10 ->AS1 AS56
->AS23 AS23 ->AS36
# [6] AS36 ->AS1 AS123->AS568 AS568->AS2 AS2
->AS45 AS45 ->AS36
# [11] AS36 ->AS1 AS79 ->AS1
G.