[R] Confounded data frame column names
Uwe Ligges
ligges at statistik.uni-dortmund.de
Wed Oct 6 08:59:23 CEST 2004
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.
Not exactly. R uses partial matching here. Iff "x11" and "x1" exists,
"x11" will be selected. Pretty much like matching for arguments in
functions.
Probably you are looking for names(temd)?
Uwe Ligges
> 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
More information about the R-help
mailing list