install.packages("igraph")
library(igraph)
edge.list<-matrix(c(0,1,0,2,0,3,2,3,3,4),byrow=TRUE,ncol=2)
edge.list
g<-graph.edgelist(el=edge.list,directed=FALSE)
plot(g,layout=layout.circle)
degree(g)
get.adjacency(g)
get.edgelist(g)
get.adjlist(g)
get.adjedgelist(g)
shortest.paths(g)
vcount(g)
ecount(g)
> edge.list<-matrix(c(0,1,0,2,0,3,2,3,3,4),byrow=TRUE,ncol=2)
> edge.list
[,1] [,2]
[1,] 0 1
[2,] 0 2
[3,] 0 3
[4,] 2 3
[5,] 3 4
> g<-graph.edgelist(el=edge.list,directed=FALSE)
> g
Vertices: 5
Edges: 5
Directed: FALSE
Edges:
[0] 0 -- 1
[1] 0 -- 2
[2] 0 -- 3
[3] 2 -- 3
[4] 3 -- 4
> plot(g,layout=layout.circle)
> degree(g)
[1] 3 1 2 3 1
> get.adjacency(g)
[,1] [,2] [,3] [,4] [,5]
[1,] 0 1 1 1 0
[2,] 1 0 0 0 0
[3,] 1 0 0 1 0
[4,] 1 0 1 0 1
[5,] 0 0 0 1 0
> get.edgelist(g)
[,1] [,2]
[1,] 0 1
[2,] 0 2
[3,] 0 3
[4,] 2 3
[5,] 3 4
> get.adjlist(g)
[[1]]
[1] 1 2 3
[[2]]
[1] 0
[[3]]
[1] 0 3
[[4]]
[1] 0 2 4
[[5]]
[1] 3
> get.adjedgelist(g)
[[1]]
[1] 0 1 2
[[2]]
[1] 0
[[3]]
[1] 1 3
[[4]]
[1] 2 3 4
[[5]]
[1] 4
> shortest.paths(g)
[,1] [,2] [,3] [,4] [,5]
[1,] 0 1 1 1 2
[2,] 1 0 2 2 3
[3,] 1 2 0 1 2
[4,] 1 2 1 0 1
[5,] 2 3 2 1 0
> vcount(g)
[1] 5
> ecount(g)
[1] 5
>