I am looping through a variable "i" in a for loop and want to reassign a value to "i" based on the outcome of an if statement. Example below.
for (i in 1:nrow(df)) {
if (df[i, 5] > 4) {
i <- 1
} else {
df[i, 5] <- df[1, 5] - 1
}
}
The script works as expected if I manually run it multiple times, but it doesn't seem to be reassigning i correctly and/or registering it in the loop. Ideas? Suggestions? Thanks in advance!