将值比较为null.为什么会这样呢? [英] Compare a value to null. Why is this true?
本文介绍了将值比较为null.为什么会这样呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么是
isTRUE(NULL != 2)
[1] FALSE
我将如何获得TRUE?
And how would I receive TRUE?
在我的真实情况下,我有变量,并且如果值不同,我想处理一些东西.但是,当一个值为NULL时,我不会将它们识别为不同!
In my real case I have variables and I want to process something, if the values differ. However, when one value is NULL I don't recognize them as different!
推荐答案
正如@Roland指出的那样,我们不能直接在NULL
对象上执行任何逻辑运算.为了比较它们,我们可能需要执行is.null
的附加检查,然后执行逻辑比较.
As @Roland pointed out, we can't perform any logical operations directly on NULL
object. To compare them we might need to perform an additional check of is.null
and then perform the logical comparison.
我们可以使用identical
来比较处理整数和NULL
的值.
We can use identical
instead to compare values which handles integers as well as NULL
.
identical(4, 2)
#FALSE
identical(NULL, 2)
#FALSE
identical(2, 2)
#TRUE
这篇关于将值比较为null.为什么会这样呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文