[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Subgraph edges
From: |
Tamas Nepusz |
Subject: |
Re: [igraph] Subgraph edges |
Date: |
Sun, 30 Oct 2016 03:33:42 +0800 |
> Maybe stupid question, but when using subgraph.edges using an index, it
> returns the wrong edge and/or re-names the vertices.
It renames the vertices indeed; basically, vertex IDs in igraph's R
interface are always in the range [1; N] if you have N vertices.
> For a graph g, say I want to subgraph to the first edge, which in the case
> below is 1–3. I try subgraph.edges(g, 1) but it returns the wrong edge.
It returns the correct edge, but since the vertex IDs in the subgraph
have to be continuous, it "renames" vertex 3 into vertex 2. If you
want to keep track of the vertex identities, assign a unique
identifier attribute to each vertex; typically the "name" vertex
attribute is used for this purpose:
> set.seed(1)
> g <- sample_gnm(5, 5)
> g
IGRAPH U--- 5 5 -- Erdos renyi (gnm) graph
+ attr: name (g/c), type (g/c), loops (g/l), m (g/n)
+ edges:
[1] 1--3 2--3 1--4 1--5 4--5
> V(g)$name <- LETTERS[1:vcount(g)]
> g
IGRAPH UN-- 5 5 -- Erdos renyi (gnm) graph
+ attr: name (g/c), type (g/c), loops (g/l), m (g/n), name (v/c)
+ edges (vertex names):
[1] A--C B--C A--D A--E D--E
> subgraph.edges(g, 1)
IGRAPH UN-- 2 1 -- Erdos renyi (gnm) graph
+ attr: name (g/c), type (g/c), loops (g/l), m (g/n), name (v/c)
+ edge (vertex names):
[1] A--C
Note that the "name" vertex attribute is special in the sense that if
such an attribute is present, igraph will use this attribute when
printing the vertices.
T.