I have a situation where I need to test whether a variable is factor(0)
but any logical test (including comparing to NULL) I try to assign to it gives logical(0)
. How do I test if something is an empty factor?
edit: allow me to elaborate.
I have a function and it looks at the attribute of the vector that it takes in, but not every vector has that the attribute, so for vectors that don't have the attribute, when I query the attribute attr(vector,"attribute")
my return is factor(0) but when I compare that to 0 I get logical(0)
and comparing it to null or NA also won't work. Any ideas?
factor(0)
is not an empty factor. You've created afactor
of the number zero with one level.... What are you trying to do?identical(x, factor(0))
to test if an object is afactor
with number zero. Not sure if that is what you are really looking for thoughif (length(x)){...}
will evaluate...
if and only ifx
is nonempty...