I'm having some trouble working with the iGraph package with R. Specifically when i'm trying to get all the nodes within 2 degrees of separation from a given node then use that list to run some operations on via a function.
I'm not super confident with how lists in R work, let alone iGraph.vs classes either.
Ideally I would want to generate a list of the vertices using the ego
to the second degree Listnode_test <- (ego(Graph1, 2, "accumsan"))
. This returns Listnode_test
. Here's the output:
structure(list(structure(c(1L, 3L, 5L, 9L, 10L, 11L, 16L, 24L,
1 c(1, 3, 5, 9, 10, 11, 16, 24, 32, 59, 64, 2, 4, 6, 14, 15, 1
The problem is that I want it to return a list of the nodes ideally in just a list that says "node1, node2, node3"
etc.. so that I can run them through a function like this:
for (i in 1:length(Listnode_test[[1]]))
{
Perspective <- 1
Listnode <- neighborhood.size(Graph1, 1, Listnode_test[[1]][i], mode="in")
##a save script either to a DF or global env
}
Basically I want to get a node, then get a list of every node that's connected to it within X degree's of separation. After I've generated this list I want to feed it into the function which calculates the in-degree for each node in the list provided.
Any help would be greatly appreciated. I've provided an example of the vertices DF below:
> vertices
from to query
1 accumsan a Benefit
2 nonummy a Benefit
3 mollis a Benefit
4 velit a Benefit
5 et a Benefit
6 vulputate a Benefit
7 magna a Benefit
8 et a Risk
9 feugiat ac Benefit
10 feugiat ac Sequential
11 mollis accumsan Benefit
12 a accumsan Benefit
13 mauris accumsan Benefit
14 et accumsan Benefit
15 fermentum accumsan Other
16 mollis accumsan Scope