[R] Column name containing "-"

David Winsemius dwinsemius at comcast.net
Tue Jan 24 15:35:01 CET 2012


On Jan 24, 2012, at 4:44 AM, Ivan Calandra wrote:

> Hi Mark,
>
> I cannot tell you why (maybe someone else can), but the check.names  
> argument to data.frame() interpret "a.-5" as an unvalid name and  
> convert to to a valid one. What I don't understand is why it isn't  
> "valid" since it works anyway.

The dash is not a valid character for column names. What do you mean  
by "it works anyway"?

-- 
David.
>
> You can set up the check.names argument to FALSE when you call  
> data.frame().
>
> HTH,
> Ivan
>
> -------- Message original --------
> Sujet: 	[R] Column name containing "-"
> Date : 	Tue, 24 Jan 2012 20:34:07 +1100
> De : 	Mark Seeto <markseeto at gmail.com>
> Pour : 	r-help at r-project.org
>
>
>
> I'm trying to create a data frame in which some of the column names
> contain a dash "-". A simple example:
>
> d<- data.frame(x = c(0, 1))
> d<- data.frame(d, y = c(0,1))
> names(d)[2]<- "a.-5"
> d
>  x a.-5
> 1 0    0
> 2 1    1
>
> d<- data.frame(d, y = c(0,1))
> d
>  x a..5 y
> 1 0    0 0
> 2 1    1 1
>
> names(d)[2]<- "a.-5"
> d
>  x a.-5 y
> 1 0    0 0
> 2 1    1 1
>
> Why does the "a.-5" column name change to "a..5" when another column  
> is added?
>
> Thanks,
> Mark Seeto
>
> ______________________________________________
> 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.
>
>
>
>
> -- 
> Ivan CALANDRA
> Université de Bourgogne
> UMR CNRS/uB 6282 Biogéosciences
> 6 Boulevard Gabriel
> 21000 Dijon, FRANCE
> +33(0)3.80.39.63.06
> ivan.calandra at u-bourgogne.fr
>
> ______________________________________________
> 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
West Hartford, CT



More information about the R-help mailing list