[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [igraph] vcount(g) and V(g) with missing items

**From**: |
Tamas Nepusz |

**Subject**: |
Re: [igraph] vcount(g) and V(g) with missing items |

**Date**: |
Mon, 12 Jul 2010 10:54:18 -0400 |

Hi,
Two things. First, when you do this:
>* g <- graph.empty(n=max_items, directed=TRUE)*
>* g <- graph( igraph_data,n=max_items, directed=TRUE )*
This means that first you construct an empty graph with 9 items, then you
construct another one from your given data and throw the first one away. The
first call to graph.empty is unnecessary.
Second, note that igraph uses numeric vertex IDs by default, and they must
always be consecutive (i.e. from 0 to |V|-1, where |V| is the number of
vertices). When using the graph() constructor, igraph_data is assumed to
contain vertex IDs. Since the largest number in igraph_data is 9, this means
that |V| = 10, even though not all of the IDs are used. I suggest you use the
graph.data.frame constructor instead, this constructs a graph from a data frame
that contains a *symbolic* edge list. In this case, the numbers in the data
frame will not be interpreted as edge IDs directly; igraph will invent edge IDs
on the fly and assign the numbers to a vertex attribute called "name":
>* m <- matrix(c(0,1,1,2,4,5,5,6,6,7,7,8,8,9,0,9), ncol=2, byrow=T)*
>* m*
[,1] [,2]
[1,] 0 1
[2,] 1 2
[3,] 4 5
[4,] 5 6
[5,] 6 7
[6,] 7 8
[7,] 8 9
[8,] 0 9
>* g <- graph.data.frame(m)*
>* vcount(g)*
[1] 9
>* V(g)$name*
[1] "0" "1" "4" "5" "6" "7" "8" "2" "9"
--
Tamas