Re: [R] "nonstandard" column names

From: <Bill.Venables_at_csiro.au>
Date: Tue, 22 Jan 2008 09:55:26 +1000

Eh? I think x$"CPI/RPI" does work. See below, with two other ways.

> m <- data.frame(x = 1:3, "CPI/RPI" = 4:6, check.names = FALSE)
> m

  x CPI/RPI

1 1       4
2 2       5
3 3       6


> m$"CPI/RPI" ### works for me!

[1] 4 5 6

> m[, "CPI/RPI"]

[1] 4 5 6

> m[["CPI/RPI"]]

[1] 4 5 6    

Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA

Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile:                         +61 4 8819 4402
Home Phone:                     +61 7 3286 7700
mailto:Bill.Venables_at_csiro.au
http://www.cmis.csiro.au/bill.venables/

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Moshe Olshansky
Sent: Tuesday, 22 January 2008 9:37 AM
To: r-help_at_r-project.org
Subject: [R] "nonstandard" column names

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.



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.

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. Received on Tue 22 Jan 2008 - 00:04:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Jan 2008 - 00:30:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive