[R] "nonstandard" column names

Bill.Venables at csiro.au Bill.Venables at csiro.au
Tue Jan 22 00:55:26 CET 2008


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.



More information about the R-help mailing list