[R] Confounded data frame column names

Spencer Graves spencer.graves at pdf.com
Wed Oct 6 00:31:31 CEST 2004


How about: 

 > DF <- data.frame(x11=1)
 > c("x1", "x11") %in% names(DF)
[1] FALSE  TRUE

hope this helps.  spencer graves

Booker, Andrew J wrote:

>This is probably a know problem (problem for me anyway) in R but I
>don't quite know what to search for in help archives. When I name a
>column "x11" in a data frame R thinks a column named "x1" exists. In
>my application I am trying to test for the existence of a column, then
>add it if it's not there. Here is a simple example:
>
>  
>
>>temd <- data.frame(x11=c(0:10))
>>is.null(temd[["x1"]])
>>    
>>
>[1] FALSE
>  
>
>>temd[["x1"]]
>>    
>>
> [1]  0  1  2  3  4  5  6  7  8  9 10
>  
>
>>temd$x1
>>    
>>
> [1]  0  1  2  3  4  5  6  7  8  9 10
>  
>
>>temd[,"x1"]
>>    
>>
>Error in "[.data.frame"(temd, , "x1") : undefined columns selected
>  
>
>
>This is in R 2.0.0.
>
>Anyone know how to run (safely) through a list of names like "x1"-"x100" and check for data frame columns with the names?
>
>
>
>----------------------------------------------------------- 
>* Opinions herein are mine only *
>----------------------------------------------------------- 
>
>			Andrew Booker 	
>			The Boeing Company
>			P.O. Box 3707 MC 7L-22
>			Seattle, WA  98124-2207
>			425-865-3573
>			FAX# 425-865-2966
>			andrew.j.booker at boeing.com
>
>______________________________________________
>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
>  
>

-- 
Spencer Graves, PhD, Senior Development Engineer
O:  (408)938-4420;  mobile:  (408)655-4567




More information about the R-help mailing list