Adr*_*sey 0 loops for-loop r while-loop
我的程序中以前工作的 for 循环都没有按预期运行。我想知道我是否对 RStudio 环境/配置做了一些操作来打破 for 循环?...或者也许,我在这里缺少一些非常基本的东西?
考虑一个基本的 for 循环示例,例如
for (year in 2010:2015){
print(paste("The year is", year))}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,即使这个循环也没有向我的控制台返回任何内容。现在,考虑一个基本的 while 循环,比如说
count <- 0
while (count <10) {
print(count)
count = count +1}
Run Code Online (Sandbox Code Playgroud)
这个 while 循环返回预期的
[1] 0
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
Run Code Online (Sandbox Code Playgroud)
我在输入这个问题时继续进行故障排除,并实际上解决了问题——尽管我仍然不清楚导致问题的原因。
我分离了一个我曾尝试合并到我的程序中的包
detach(package:magicfor)
Run Code Online (Sandbox Code Playgroud)
并重新启动 RStudio。可能,我只是不明白 magicfor 试图为我做什么,即使没有在我的脚本中明确调用它。
这非常令人沮丧,我可能花了 3 个多小时对复杂的循环进行故障排除,而这完全是另一回事。我希望本文档对你们中的一些人有所帮助。
| 归档时间: |
|
| 查看次数: |
1818 次 |
| 最近记录: |