Let's say I have the following vector:
vec = c(29, 30, 15, 29, 17, 25, 24, 28, 25, 24, 28, 25, 24, 28, 25, 24, 28)
You'll notice there are three repeating elements (25, 24, and 28). How can I get R to recognize when there are repeating elements (or cycles) in a vector? I want to detect this no matter how many elements are repeating (2 or 5 rather than 3) and no matter how many elements into the vector it starts.
For context, I've got an algorithm that is trying to converge on a value, but sometimes it gets stuck in this repeating loop. I want R to detect when it's stuck in this infinite loop and get out. The vec
in my example is a log of the value at each iteration.
I've figured out how I can catch double repeating elements (saving the value from the last iteration to compare to the current iteration) but this 3+ repeating elements has me puzzled.