|
From: | Gábor Csárdi |
Subject: | Re: [igraph] injecting a network and simulating it. |
Date: | Thu, 25 Apr 2013 13:02:48 -0400 |
thanks.In below ,How can i control the percentage of both 1 and 2,say 20% of 1 and rest 2?
V(net)$Opinion <- sample(1:2, vcount(net), replace=TRUE)Sorry,this is R question though,may beRegardsSuvirOn Thu, Apr 25, 2013 at 4:37 PM, Gábor Csárdi <address@hidden> wrote:
On Thu, Apr 25, 2013 at 10:34 AM, Gábor Csárdi <address@hidden> wrote:
I see. Then what you could do is adding a vertex attribute, named (say) "Opinion", and then update that based on the network structure, e.g. (in R):Sorry, sent it prematurely, this is the correct code:library(igraph)set.seed(42)net <- erdos.renyi.game(40, 2/40)V(net)$Opinion <- sample(1:2, vcount(net), replace=TRUE)coords <- layout.auto(net)colbar <- c("orange", "cyan")layout(rbind(1:2))par(mar=c(0,0,0,0))plot(net, vertex.color=colbar[V(net)$Opinion], layout=coords)## Set the opinion based on the neighborsV(net)$Opinion <- sapply(V(net), function(x) {if (degree(net, x)==0) {V(net)$Opinion[x]} else {round(mean(V(net)$Opinion[neighbors(net,x)]))}})plot(net, vertex.color=colbar[V(net)$Opinion], layout=coords)G.[...]_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help
_______________________________________________
igraph-help mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/igraph-help
[Prev in Thread] | Current Thread | [Next in Thread] |