本文介绍了if/while (condition) {: 缺少 TRUE/FALSE 需要的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误消息:

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

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

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

What does it mean, and how do I prevent it?

推荐答案

condition 的评估结果为 NA.if 条件必须具有 TRUEFALSE 结果.

The evaluation of condition resulted in an NA. The if conditional must have either a TRUE or FALSE result.

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

由于计算结果,这可能会意外发生:

This can happen accidentally as the results of calculations:

if(TRUE && sqrt(-1)) {}
## Error in if (TRUE && sqrt(-1)) { : missing value where TRUE/FALSE needed

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

另见相关错误:

if/while(条件)错误{:参数长度为零

if/while(条件)错误:参数不可解释为逻辑

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

这篇关于if/while (condition) {: 缺少 TRUE/FALSE 需要的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 02:34