[R] Error in `[.data.frame`... undefined columns selected

David Winsemius dwinsemius at comcast.net
Mon Nov 19 06:23:10 CET 2012


On Nov 18, 2012, at 6:34 PM, Eiko Fried wrote:

> When I run this script on 9 variables, it works without problems.
>
> Z <-
> data
> [,c
> ("s1_1234_m
> ","s2_1234_m
> ","s3_1234_m
> ","s4_1234_m
> ","s5_1234_m","s6_1234_m","s7_1234_m","s8_1234_m","s9_1234_m"
> )]
>
> However, when I run the script on 9 different variables, it does not  
> work:
> Z <-
> data 
> [,c 
> ("d_s1_m 
> ","d_s2_m 
> ","d_s3_m","d_s4_m","d_s5_m","d_s6_m","d_s7_m","d_s8m","d_s9m"
> )]
>
> Error in `[.data.frame`(data, , c("d_s1_m", "d_s2_m", "d_s3_m",  
> "d_s4_m",
> :
>  undefined columns selected

You have probably misspelled one or more the column names. For  
instance I suspect that one or both of these might be lacking a second  
"_" : "d_s8m","d_s9m"

If you feel thsi is wrong then you at the very least need to offer  
str(data)

BTW, data is the name of a perfectly good function, so naming your  
dataframe "data" is likely to create confusion.

-- 
David.
>
> The first 9 variables are between 0 and 3, there are no missing  
> values in
> the dataset.
>
> The second 9 variables are between -3 and 3, there are no missing  
> values in
> the dataset.
>
> I am pretty new to R and have no idea what could cause this error.
>
> Thank you
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list