Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test if variable is empty in R

Tags:

r

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?

like image 714
Carl Avatar asked Aug 20 '15 14:08

Carl


1 Answers

I was able to use length==0 thanks for the help

like image 160
Carl Avatar answered Oct 24 '22 17:10

Carl