[R] does column exist?

apjaworski@mmm.com apjaworski at mmm.com
Thu May 19 19:53:24 CEST 2005






There may be a simpler way, but this

is.na(match("X", names(df)))

should return TRUE if the column name exists and FALSE otherwise.

Cheers,

Andy

__________________________________
Andy Jaworski
518-1-01
Process Laboratory
3M Corporate Research Laboratory
-----
E-mail: apjaworski at mmm.com
Tel:  (651) 733-6092
Fax:  (651) 736-3122


                                                                           
             Omar Lakkis                                                   
             <uofiowa at gmail.co                                             
             m>                                                         To 
             Sent by:                  r-help at stat.math.ethz.ch            
             r-help-bounces at st                                          cc 
             at.math.ethz.ch                                               
                                                                   Subject 
                                       [R] does column exist?              
             05/19/2005 12:42                                              
             PM                                                            
                                                                           
                                                                           
             Please respond to                                             
                Omar Lakkis                                                
             <uofiowa at gmail.co                                             
                    m>                                                     
                                                                           
                                                                           




How do I test if a data.frame has a column named X?
exists(o) checks if the object exists or not, I want to test if a
data.frame object (df) has a column names(X), something like:
exists(df$X)

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list