I had to use a similar code on some work I had to do and got this error. Basically I can´t understand why R says that the remainder of 234/6.5 is 6.5 when inside the loop bu