I have a basic for loop with a simple matrix. The code is doing what it is
supposed to do, but I'm still wondering the error "subscript out of
bounds". What would be a smoother way to code such a basic for loop?

myMatrix <- matrix(0,5,12)
for(i in 1:nrow(myMatrix)) {
  for(i in 1:ncol(myMatrix)) {
    myMatrix[i,i] = -1
    myMatrix[i,i+1] = 1
}}
print(myMatrix)

Thanks in advance!

        [[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.

Reply via email to