Reputation: 1305
This question pertains to the calling of vertices in Igraph.
Lets say we have a directed graph
g<-graph(c(1:10),directed=T)
and i want to find the vertices pointing to vertex 2.
Lets say you want to find the vertices pointed "to" vertex 1.
Why won't using the "to" condition work
V(g)[to(1)]
but rather this?
V(g)[nei(1,"to")]
Upvotes: 1
Views: 338
Reputation: 47551
It works for me?
> g<-graph(c(1:10),directed=T)
> V(g)[to(1)]
Vertex sequence:
[1] 2
> V(g)[nei(1,"to")]
Vertex sequence:
[1] 2
Personally I like working with edgelists. Alternatively you could do it like this:
# Get edgelist:
E <- get.edgelist(g)
# To 1 in directed graph:
E[E[,2]==1,1]
# Connected to 1 in undirected graph:
c(E[E[,2]==1,1],E[E[,1]==1,2])
Upvotes: 1
Reputation: 48051
to
works only with edge sequences; e.g., E(g)[to(1)]
gives you all the edges that point to vertex 1. IMHO this is quite logical since vertices do not "point" anywhere (the edges do) so it does not make sense to use from
or to
.
Also, the "official" way of using nei
is nei(1, "out")
and not nei(1, "to")
although it could be the case that "to"
works as well. You can use outnei(1)
as well.
Disclaimer: I am one of the authors of igraph although I did not write the R interface so there might be a better reason than the one I explained above.
Upvotes: 0