@e4e5f4 is correct in that your main problem is that you are using (
round brackets were you need [
square brackets.
However, in addition, you have an issue inside your for
loop:
# this is a problem, even with brackets corrected
N1[t+1]= N1[t] + r1*N1[t]*(K1 - N1 - a12*N2)/K1
N1[t+1]= N1[t] + r1*N1[t]*(K1 - N1 - a12*N2)/K1
^ ^
N1 & N2 are vectors
Since most mathematical operations in R
are vectorized, the value being assigned (ie, the right hand side of your equation) is a vector whose length is growing at every iteration.
The subsequent warnings you are seeing come from trying to assign multiple values (ie a vector) into a single element of a vector.
You will see the same error if you try
foo <- c(17, 23, 31)
foo[3] <- 1:10
You are getting 158 of these warnings because you are iterating.
You most likely want to index those values (likely with N1[[t]]
or N1[[t-1]]
, etc)