Hi - I'm trying to generate the (toy) matrix below in R. I get the error message shown below (and no matrix!) and I'm unclear as to why - if someone could advise as to why, that would be ace. Thank you! Michelle
0.7 0 0.1 0 0.1 0 0 0 0 0 0 0 0.1 0.7 0.1 0.1 0.1 0.1 0 0 0 0 0 0 0.1 0.1 0.7 0 0.1 0 0.1 0 0 0 0 0 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0 0 0 0 0.1 0.1 0.1 0.1 0.7 0 0.1 0 0.1 0 0 0 0 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0 0 0 0 0.1 0.1 0.1 0.1 0.7 0 0.1 0 0.1 0 0 0 0 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0 0 0 0 0.1 0.1 0.1 0.1 0.7 0 0.1 0 0 0 0 0 0 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0 0 0 0 0 0 0.1 0.1 0.1 0.1 0.7 0 0 0 0 0 0 0 0 0.1 0.1 0.1 0.1 0.7 cross = 0.1 diag = 0.7 n=12 # to be changed to n=1:100 once the code below is correct nbe=4 R0=sapply(n,function(x){ m = matrix(0, nrow=x, ncol=x) for (i in 1:x) { for(j in 1:x) { if (i==j) { m[i,j] = diag } else if(j<=i+nbe & j>=i-nbe) { m[i,j]=cross } } } for (i in seq(1,x,2)) { for (j in seq(i+1,i+nbe,2)) { m[i,j]=0 } } print(m) max(Mod(eigen(m)$value)) } ) R0 error message: Error in `[<-`(`*tmp*`, i, j, value = 0) : subscript out of bounds [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.