Reputation: 1232
I have a directed graph 'g' with 115 nodes and 1098 edges. It is a hyperlink graph (i.e. nodes are websites and edges represent existence of a hyperlink).
I want to remove all the outbound edges from all vertices that are not from a particular node of interest (id=7). I am trying to create a graph representing only the outlinks from a particular website (i.e. which websites it links to).
I have tried various attempts at using the delete.edges
function, but I am very confused about how to achieve this.
I have also tried:
g[1:6,] <- FALSE
followed by:
g[8:1098,] <- FALSE
But this doesn't work either.
Upvotes: 0
Views: 327
Reputation: 10825
I am not sure why your code does not work, it would be great to have a reproducible example, with data. I suspect that your graph has vertex names and you are mixing up the vertex names and the numeric vertex ids. Anyway, the simplest way is probably:
library(igraph)
links <- cbind(from=c( 2, 3, 7, 7, 7),
to=c(10,11,12,13,14))
g <- graph.edgelist(links)
str(g)
# IGRAPH D--- 14 5 --
# + edges:
# [1] 2->10 3->11 7->12 7->13 7->14
g[-7,] <- FALSE
str(g)
# IGRAPH D--- 14 3 --
# + edges:
# [1] 7->12 7->13 7->14
Upvotes: 1