Why does NA==NULL
result in logical (0)
instead of FALSE?
And why does NULL==NULL
result in logical(0)
instead of TRUE?
Why does NA==NULL
result in logical (0)
instead of FALSE?
And why does NULL==NULL
result in logical(0)
instead of TRUE?
NULL
is a "zero-length" object, so any elementwise comparison or operation with NULL
will have length zero: logical(0)
represents a logical vector of length zero. You might find identical()
useful: identical(NULL,NULL)
is TRUE, identical(NULL,NA)
is FALSE. Also see ?is.null
, ?is.na
for testing for the special values of NA
and NULL
.
See also: Compare a value to null. Why is this true?
@Dason points out that ==
does elementwise comparison; when you do elementwise operations on vectors of two different lengths, R typically "recycles" the shorter vector to be equal in length to the longer one (with a warning if the lengths are not evenly divisible), but the R language definition says
As from R 1.4.0, any arithmetic operation involving a zero-length vector has a zero-length result.