Re: [R] "nonstandard" column names

From: Ted Harding <Ted.Harding_at_manchester.ac.uk>
Date: Mon, 21 Jan 2008 23:56:06 -0000 (GMT)


On 21-Jan-08 23:36:46, 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.

I'm a bit surprised that x$"CPI/RPI" doesn;t work, since I just got it to work with:

> D

  A B/C
1 1 2
2 3 4
3 5 6

D$"B/C"
[1] 2 4 6

Are you sure the name really is "CPI/RPI"? In setting yp my example, I read in a CSV file "temp.csv":

A,B/C
1,2
3,4
5,6

with

D<-read.csv("temp.csv")

and got:

> D

  A B.C
1 1 2
2 3 4
3 5 6

so read.csv() had changed the name from "B/C" to "B.C". I had to do

names(D)<-c("A","B/C")

to bring it back to the example above.

Best wishes,
Ted.



E-Mail: (Ted Harding) <Ted.Harding_at_manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861
Date: 21-Jan-08                                       Time: 23:56:02
------------------------------ XFMail ------------------------------

______________________________________________
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:07:05 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