I keep getting an error when N > 399

So I've been trying to make a code to count the number of mutations
So I wrote my own function, countMut() that mutates a sequence for N number of times.
The problem is that whenever I set N > 399, I get this error message:

Error in if (oriAA[mutAAloc] == mutAA[mutAAloc]) { : argument is of length zero

And also I get this error sometimes when the N < 399 and sometimes I don't. I don't understand what this means... How can I fix it?

The if statement codes are here:
if (oriAA[mutAAloc] == mutAA[mutAAloc]) { SilCount <- SilCount + 1 }

Thank you for your help!