R for 循环跳到下一次迭代 ifelse [英] R for loop skip to next iteration ifelse

查看:40
本文介绍了R for 循环跳到下一次迭代 ifelse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你有一个像这样的 for 循环

Suppose you have a for loop like so

for(n in 1:5) {
  #if(n=3) # skip 3rd iteration and go to next iteration
  cat(n)
}

如果满足某个条件,如何跳到下一次迭代?

How would one skip to the next iteration if a certain condition is met?

推荐答案

for(n in 1:5) {
  if(n==3) next # skip 3rd iteration and go to next iteration
  cat(n)
}

这篇关于R for 循环跳到下一次迭代 ifelse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆