Error in allvalues[[i%%length(allvalues) + 1]] : subscript out of bounds