Re: [R] space in column name
Farrel Buchinsky-3 wrote: I read a table from Microsoft Access using RODBC. Some of the variables had a name with a space in it. R has no problem with it but I do. I cannot find out how to specify the space names(alltime) [1] IDLVL7 Ref Pv No Ref Pv Name DOS Pt Last Name Pt First Name MRN CPT CPT Desc DxCd1 DxCd2 DxCd3 DxCd4 [15] DOE But what do I do if I want to do something such as this alltime[grep(MIDDLE EAR EXPLORE,alltime$CPT Desc,] Error: unexpected symbol in alltime[grep(MIDDLE EAR EXPLORE,alltime$CPT Desc Farrel Buchinsky The following might work: alltime[grep(MIDDLE EAR EXPLORE,alltime[[ CPT Desc ]] ] -Charlie - Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://www.nabble.com/space-in-column-name-tp24559626p24559726.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] space in column name
cls59 wrote: The following might work: alltime[grep(MIDDLE EAR EXPLORE,alltime[[ CPT Desc ]] ] -Charlie ACK! Terribly sorry about the double post- but I forgot to close the quote. It should be: alltime[grep(MIDDLE EAR EXPLORE,alltime[[ CPT Desc ]] ] Maybe I should wait until AFTER my morning coffee to browse R-help... - Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://www.nabble.com/space-in-column-name-tp24559626p24559754.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] space in column name
I sifted some more and read about a workaround for the problem. I could simply rename the columns so that there were no more spaces names(alltime) -gsub( ,., names(alltime)) names(alltime) [1] IDLVL7 Ref.Pv.No Ref.Pv.Name DOS Pt.Last.Name Pt.First.Name MRN CPT CPT.Desc DxCd1 DxCd2 DxCd3 DxCd4 [15] DOE Farrel Buchinsky Google Voice Tel: (412) 567-7870 Sent from Pittsburgh, Pennsylvania, United States On Sun, Jul 19, 2009 at 14:32, Farrel Buchinsky fjb...@gmail.com wrote: I read a table from Microsoft Access using RODBC. Some of the variables had a name with a space in it. R has no problem with it but I do. I cannot find out how to specify the space names(alltime) [1] IDLVL7 Ref Pv No Ref Pv Name DOS Pt Last Name Pt First Name MRN CPT CPT Desc DxCd1 DxCd2 DxCd3 DxCd4 [15] DOE But what do I do if I want to do something such as this alltime[grep(MIDDLE EAR EXPLORE,alltime$CPT Desc,] Error: unexpected symbol in alltime[grep(MIDDLE EAR EXPLORE,alltime$CPT Desc Farrel Buchinsky Sent from Pittsburgh, Pennsylvania, United States [[alternative HTML version deleted]] __ 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.
Re: [R] space in column name
use 'make.names' make.names(MIDDLE EAR EXPLORE) [1] MIDDLE.EAR.EXPLORE On Sun, Jul 19, 2009 at 2:32 PM, Farrel Buchinskyfjb...@gmail.com wrote: I read a table from Microsoft Access using RODBC. Some of the variables had a name with a space in it. R has no problem with it but I do. I cannot find out how to specify the space names(alltime) [1] ID LVL7 Ref Pv No Ref Pv Name DOS Pt Last Name Pt First Name MRN CPT CPT Desc DxCd1 DxCd2 DxCd3 DxCd4 [15] DOE But what do I do if I want to do something such as this alltime[grep(MIDDLE EAR EXPLORE,alltime$CPT Desc,] Error: unexpected symbol in alltime[grep(MIDDLE EAR EXPLORE,alltime$CPT Desc Farrel Buchinsky Sent from Pittsburgh, Pennsylvania, United States [[alternative HTML version deleted]] __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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.
Re: [R] space in column name
Farrel Buchinsky-3 wrote: I sifted some more and read about a workaround for the problem. I could simply rename the columns so that there were no more spaces names(alltime) -gsub( ,., names(alltime)) That would certainly be a solution. The method I was trying to demonstrate is that in addition to using the $ sign syntax, lists and data.frames can be accessed using strings- much like a hash. In order to do so, you must use the [[]] or [] methods. For example, just as you can do the following for a vector: x - c(1,3,5) for( i in 1:length(x) ){ print( x[ i ] ) } You could do something similar for your data.frame: for( i in names(alltime) ){ print( alltime[[ i ]] ) } The important thing to note is that if you tried to use alltime$i in the above loop, you would get a bunch of NULLS as there is no component named 'i'. Hope that helps! -Charlie - Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://www.nabble.com/space-in-column-name-tp24559626p24559869.html Sent from the R help mailing list archive at Nabble.com. __ 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.