Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare a value to null. Why is this true?

Why is

isTRUE(NULL != 2)
[1] FALSE

And how would I receive TRUE?

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!

like image 706
agoldev Avatar asked Jun 27 '17 07:06

agoldev


Video Answer


1 Answers

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.

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
like image 172
Ronak Shah Avatar answered Oct 05 '22 20:10

Ronak Shah