I am looping over a vector and I would like to know how to "skip" an iteration based on the last iteration.
For example: The first iteration will hit the 1, then the second will hit another 1, but I would like to skip that iteration IF the number is the same as the previous number.
Simple example:
vector <- c(1, 1, 1, 2, 3, 3, 4)
for (i in vector) {
print(i)
}
I do not want the iteration to print out "1" three times. I want it to skip to the next iteration until it reaches the 2. This needs to be dynamic as the real vector is much more complicated.
Vice versa, maybe I want to perform the next iteration, only if the iteration before it is the same.