小编Dig*_*ngh的帖子

为什么以下 R 代码由于第一个 if 条件后缺少大括号而失败?

以下 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 条件的结构,找到了这个页面,其中写着大括号是可选的。那么为什么代码会失败呢?

syntax if-statement r

0
推荐指数
1
解决办法
51
查看次数

标签 统计

if-statement ×1

r ×1

syntax ×1