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 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")> DFCPI/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
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) > mx 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.
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:> DA 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:> DA 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 ------------------------------
Thanks to all those who responded! Now the obvious thing (putting the column name into double quotes) works for me too. But it didn't work yesterday! I have no explanation for this. Moshe. --- Moshe Olshansky <m_olshansky at yahoo.com> 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. > > ______________________________________________ > 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. >
Hi everyone, I've got a set of thousands points (2D) located on a pixel image, and I know that four points in this pixels image correspond to four points in a real space on which I need to locate the mapping of all the thousand source points from the pixel set. For this I've got four reference points (corners.px), and the corresponding four destination points (corners.r):> corners.px[,1] [,2] [1,] 212.5 275.5 [2,] 562.5 275.5 [3,] 212.5 625.5 [4,] 562.5 625.5> corners.r[,1] [,2] [1,] 139463 8386 [2,] 139579 -1294 [3,] 131921 8180 [4,] 132002 -1256 I think I must find a transformation matrix and apply this transformation matrix to all the set in the pixel space, but cannot find the way to contruct this transformation matrix. I guess this is not a question just pertaining to R, but perhaps you can help me with this. Thank you and best regards! Javier -----