gpt4 book ai didi

r - if/while(condition){: missing Value where TRUE/FALSE needed

转载 作者:行者123 更新时间:2023-12-03 07:44:43 26 4
gpt4 key购买 nike

我收到此错误消息:

Error in if (condition) { : missing value where TRUE/FALSE needed

要么
Error in while (condition) { : missing value where TRUE/FALSE needed

这是什么意思,我该如何预防?

最佳答案

condition的求值得到了NA。条件if必须具有TRUEFALSE结果。

if (NA) {}
## Error in if (NA) { : missing value where TRUE/FALSE needed

计算结果可能会偶然发生:
if(TRUE && sqrt(-1)) {}
## Error in if (TRUE && sqrt(-1)) { : missing value where TRUE/FALSE needed

要测试是否缺少对象,请使用 is.na(x) 而不是 x == NA

另请参阅相关错误:

Error in if/while (condition) { : argument is of length zero

Error in if/while (condition) : argument is not interpretable as logical
if (NULL) {}
## Error in if (NULL) { : argument is of length zero

if ("not logical") {}
## Error: argument is not interpretable as logical

if (c(TRUE, FALSE)) {}
## Warning message:
## the condition has length > 1 and only the first element will be used

关于r - if/while(condition){: missing Value where TRUE/FALSE needed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22888438/

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