gpt4 book ai didi

r - if/while(condition){:参数长度为零时出错

转载 作者:行者123 更新时间:2023-12-03 08:46:58 25 4
gpt4 key购买 nike

我收到了错误

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

要么
Error in while (condition) { : argument is of length zero

导致此错误消息的原因是什么?

经过进一步检查,似乎该值为 NULL
condition
## NULL

为了处理此错误,如何测试NULL值?

我期望这将返回 TRUE,但是我得到了一个空的逻辑值:
condition == NULL
## logical(0)

最佳答案

参见?NULL
您必须使用is.null

‘is.null’ returns ‘TRUE’ if its argument is ‘NULL’ and ‘FALSE’ otherwise.



尝试这个:
if ( is.null(hic.data[[z]]) ) { print("is null")}

R Language Definition的2.1.6节开始

There is a special object called NULL. It is used whenever there is a need to indicate or specify that an object is absent. It should not be confused with a vector or list of zero length. The NULL object has no type and no modifiable properties. There is only one NULL object in R, to which all instances refer. To test for NULL use is.null. You cannot set attributes on NULL.

关于r - if/while(condition){:参数长度为零时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12307139/

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