1){print("aa")} els-6ren">
gpt4 book ai didi

r - R中的函数 "else"

转载 作者:行者123 更新时间:2023-12-01 11:00:19 25 4
gpt4 key购买 nike

我在使用 R 中的函数 else 时遇到了一些困难。当我输入 ?else 时,我没有得到关于函数 else 的任何帮助。

当我运行以下程序时:

i=1

if(i>1){print("aa")}

else{print("bb")}

else 无效。有人可以告诉我原因吗?

最佳答案

获取帮助类型

?'else'

查看帮助中的段落

Note that it is a common mistake to forget to put braces ({ .. }) around your statements, e.g., after if(..) or for(....). In particular, you should not have a newline between } and else to avoid a syntax error in entering a if ... else construct at the keyboard or via source. For that reason, one (somewhat extreme) attitude of defensive programming is to always use braces, e.g., for if clauses.

if(i>1){print("aa")
}else{print("bb")}

if(i>1){print("aa")}else{print("bb")}

大概会为您工作。

i=1

{
if(i>1){print("aa")}
else{print("bb")}
}

也可以。关键是让解析器知道需要更多输入。

关于r - R中的函数 "else",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11641743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com