Skip to content
Prev 70039 / 398506 Next

does column exist?

It depends on what Omar means by "a column named X".  Consider the 
following:

 > tstDF <- data.frame(aa=1, bb=2)
 > tstDF$a
[1] 1
 > is.null(tstDF$a)
[1] FALSE
 > is.na(match("a", names(tstDF)))
[1] TRUE

	  Does tstDF have a column named "a"?  It has a column named "aa", 
which is accessed by tstDF$a;  is.null(tstDF$a) correctly identifies its 
presence, while is.na(match("a", names(tstDF))) correctly says that "a" 
is not the official name of any column of tstDF.

	  spencer graves
apjaworski at mmm.com wrote: