[R] Column name containing "-"

Mark Seeto markseeto at gmail.com
Tue Jan 24 10:34:07 CET 2012


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



More information about the R-help mailing list