[R] Column name containing "-"

Ivan Calandra ivan.calandra at u-bourgogne.fr
Tue Jan 24 10:44:18 CET 2012


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.

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



More information about the R-help mailing list