igraph-help
[Top][All Lists]

## [igraph] how to change attributes to a randomly selected nodes of a netw

 From: mario rossi Subject: [igraph] how to change attributes to a randomly selected nodes of a network in igraph Date: Thu, 11 May 2017 16:40:46 +0200

Hi, R community!

I need to make an algorithm  that works as follow:

1) I start from a given network (for example a star: "g <- make_star(100)");

2) then, I assign to all nodes the same attribute (for example, all the nodes in the same compartment, that I call "A": "v(g)\$compartment <- rep("A", 100)" );

3) I select a random number of nodes (for example: "sample(vcount(g), 10)");

No problem with 1), 2) and 3)! But, please, can you help me with the following part of the algorithm?

4) I have to change the attribute to the randomly selected nodes (for example, if the result of the random sample of 10 nodes is

sample(vcount(g),10)

[1] 18 11 26 28 44 67 86 89 52 78,

I have to change the compartment of nodes 18, 11, 26, ..., 78 from "A" to "B");

5) I have to randomly sampling, within the nodes that still in the compartment "A" (and not in "B") a given PERCENTAGE (and not a given number) of the nodes (in this first iteration, there are 90 nodes in the compartment "A", and I want to select, for example 15% of the 90 nodes).

6) I have to change the compartment of the just randomly selected nodes from "A" to a new compartment, called "C"; (Note that this will be a part of a "repeat until" loop, so I need to obtain an algorithm that automatically turn the compartment of the randomly selected nodes from "A" to "C").

7) I need to randomly sampling, AMONG THE NODES THAT ARE ADJACENT to those in compartment "C", a given percentage of them, for example 12%, and turn these just selected nodes into a new compartment, called "D".

8) If compartment "A" is empty, the algorithm stops. Otherwise, it return at point 5)

End

Thank you in advance, if you have time to help me.

And sorry for my bad English.

Mario Rossi