【发布时间】:2020-05-20 08:29:40
【问题描述】:
我的程序中以前工作的 for 循环都没有按预期运行。 我想知道我是否对我的 RStudio env/config 做了一些事情来中断 for 循环? ...或者,我在这里缺少一些非常基本的东西?
考虑一个基本的 for 循环示例,比如说
for (year in 2010:2015){
print(paste("The year is", year))}
出于某种原因,即使这个循环也不会向我的控制台返回任何内容。现在,考虑一个基本的 while 循环,比如
count <- 0
while (count <10) {
print(count)
count = count +1}
这个while循环返回预期的
[1] 0
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
【问题讨论】:
-
您在第一个循环中缺少 }。
-
谢谢!这是问题中的错字,但不是代码。
标签: r loops for-loop while-loop