Moshe Olshansky wrote: > Hi everyone, > > I am sure that this question has been asked here some > time ago but I do not remember the answer and was > unable to find it in the archives... > > Below is my question: suppose that I have a data.frame > x and one of it's columns name is "CPI/RPI" (without > quotation marks of course). How can I reference this > column? Neither of x$CPI/RPI or x$"CPI/RPI" work. I > certainly can do x[,which(colnames(x) == "CPI/RPI")] > but there should be a nicer way to do this. > > Thank you! > > Moshe Olshansky.
Moshe, Not a problem here, using 2.6.1 patched: DF <- data.frame(A = 1:5, B = letters[1:5]) colnames(DF) <- c("CPI/RPI", "Col2") > DF CPI/RPI Col2 1 1 a 2 2 b 3 3 c 4 4 d 5 5 e > DF$"CPI/RPI" [1] 1 2 3 4 5 > DF[, "CPI/RPI"] [1] 1 2 3 4 5 > subset(DF, select = "CPI/RPI") CPI/RPI 1 1 2 2 3 3 4 4 5 5 HTH, Marc Schwartz ______________________________________________ R-help@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.