[R] Confounded data frame column names

Booker, Andrew J andrew.j.booker at boeing.com
Wed Oct 6 00:10:41 CEST 2004


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




More information about the R-help mailing list