Number of Vertex (vcount) is one more than the actual

Number of Vertex (vcount) is one more than the actual

I am learning about igraph and get stuck on vcount.

The edgelist in triangle.txt:
1 2
2 3
3 1

> g<- read_graph("triangle.txt", format="edgelist")
> g
IGRAPH 35ad1ec D--- 4 3 -- 
+ edges from 35ad1ec:
[1] 2->3 3->4 4->2
> vcount(g)
[1] 4

It is clear that the number of vertex is 3 from the edgelist, but why R give the number of vertex is 4.

I did experiment with with two other edgelists, with number of vertex 4 and 34, they gives 5 and 35.

Thank you.

I learned from one posting in the stackoverflow which do import the file first then convert it to a graph, the results are correct .

f<-read.table(file="triangle.txt")
> edges<-c()
> for (e in 1:dim(f)[1]){
+ edges<-append(edges,c(f[e,1],f[e,2]))
+ }
> g<-graph(edges,directed = FALSE)
> g
IGRAPH 9b98281 U--- 3 3 -- 
+ edges from 9b98281:
[1] 1--2 2--3 1--3
> vcount(g)
[1] 3

I did experiment with the two other edgelists and they give the correct answers.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.