gpt4 book ai didi

r - if/while(条件)出错 { : missing Value where TRUE/FALSE needed

转载 作者:行者123 更新时间:2023-12-03 04:23:35 25 4
gpt4 key购买 nike

我收到此错误消息:

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

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

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

最佳答案

条件的评估结果为NAif 条件必须有 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(条件)出错 { : missing Value where TRUE/FALSE needed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7355187/

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