以下 R 代码会导致“错误:未找到对象‘test’”。
condition <- 1
if(condition == 0)
if(condition == 1)
{
test <- "Pass"
}
print(test)
Run Code Online (Sandbox Code Playgroud)
但是,如果我在 if 条件后添加一个大括号,如下所示,那么它就可以正常工作。
condition <- 1
if(condition == 0){}
if(condition == 1)
{
test <- "Pass"
}
print(test)
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索了R 中if 条件的结构,找到了这个页面,其中写着大括号是可选的。那么为什么代码会失败呢?