Whats the best way to detect null values in a vector?
If I have the vector below and want to know that the 4th position is null how would I do that?
vx <- c(1, 2, 3, NULL, 5)
is.null()
returns only FALSE
:
is.null(vx)
# [1] FALSE
and I'd like to get:
FALSE FALSE FALSE TRUE FALSE
As mentioned in the comments,
NULL
will not appear inlength(vx)
. It is a special object in R for undefined values. From CRAN documentation:But your question can still have learning opportunities with respect to lists. It will show up there. As in:
Trying to identify the
NULL
value in a very large dataset can be tricky for novice R users. There are different techniques, but here is one that worked for me when I needed it.If there are characters, then substitute in
is.character
or whatever class applies.