I am new to R
.
I am trying to create a time-loop, where the value of a node attribute gets updated over time, if the nodes are not informed. So far, I have something like the following:
#loading required packages
library(igraph)
library(tidyverse)
library(ggraph)
library(ggnetwork)
library(tidygraph)
g <- play_erdos_renyi(10, .2)
M<-matrix(0:1, nrow = 10, ncol = 10)
Periods=10
seeds=c(1,3)
#Seeds are informed
V(g)$informed <- F
V(g)[seeds]$informed=T
#Seeds have prob 0.5 (just treat prob as any variable here)
V(g)$prob=0
V(g)[seeds]$prob=0.5
#Time loop for creating prob over time
#prob at [t+1]=M*prob at [t]
#calculate prob for vertex v in time t+1 by multiplying 10X10 matrix M with 10X1 vector V(g)$prob
#then considering the v-th row
for (t in 1:Periods) {
for(v in V(g)) {
if(!V(g)[v]$informed) {
V(g)[v]$prob[t+1]= M %*% V(g)$prob[t][v]
}}}
I am getting
Error in M %*% V(g)$prob[t][v] : non-conformable arguments
I was wondering how to fix this.