How to pause a for loop in R?
In R programming language, pausing a for loop can be achieved by using the Sys.sleep() function. This function is used to pause execution for a specific duration. You can place the Sys.sleep() function between each iteration of the for loop to achieve the pausing effect.
Below is an example:
for (i in 1:10) {
# 执行某些操作
print(i)
# 暂停1秒钟
Sys.sleep(1)
}
In the example above, the current iteration number i is printed and a 1-second pause is added before moving on to the next iteration. You can adjust the parameter in the Sys.sleep() function to control the length of the pause as needed.