Greetings I want to remove numbers from a string of characters that identify sites so that I can merge two data frames. For example, a site in one frame is called "001a Frozen Niagara Entrance" whereas the same site in the other data frame is called "Frozen Niagara Entrance". It seems to me the easiest thing to do would be to remove the numbers from the first data frame so the two will match. How do I go about removing those numbers? Thanks in advance. Cheers Kurt *************************************************************** Kurt Lewis Helf, Ph.D. Ecologist EEO Counselor National Park Service Cumberland Piedmont Network P.O. Box 8 Mammoth Cave, KY 42259 Ph: 270-758-2163 Lab: 270-758-2151 Fax: 270-758-2609 **************************************************************** Science, in constantly seeking real explanations, reveals the true majesty of our world in all its complexity. -Richard Dawkins The scientific tradition is distinguished from the pre-scientific tradition in having two layers. Like the latter it passes on its theories but it also passes on a critical attitude towards them. The theories are passed on not as dogmas but rather with the challenge to discuss them and improve upon them. -Karl Popper ...consider yourself a guest in the home of other creatures as significant as yourself. -Wayside at Wilderness Threshold in McKittrick Canyon, Guadalupe Mountains National Park, TX Cumberland Piedmont Network (CUPN) Homepage: http://tiny.cc/e7cdx CUPN Forest Pest Monitoring Website: http://bit.ly/9rhUZQ CUPN Cave Cricket Monitoring Website: http://tiny.cc/ntcql CUPN Cave Aquatic Biota Monitoring Website: http://tiny.cc/n2z1o
See agrep function: agrep("Frozen Niagara Entrance", "001a Frozen Niagara Entrance") > 0 To remove the numbers: gsub("\\d", "", "001a Frozen Niagara Entrance") On Mon, Oct 18, 2010 at 12:58 PM, <Kurt_Helf@nps.gov> wrote:> Greetings > I want to remove numbers from a string of characters that identify > sites so that I can merge two data frames. For example, a site in one > frame is called "001a Frozen Niagara Entrance" whereas the same site in > the other data frame is called "Frozen Niagara Entrance". It seems to me > the easiest thing to do would be to remove the numbers from the first data > frame so the two will match. How do I go about removing those numbers? > Thanks in advance. > Cheers > Kurt > > *************************************************************** > Kurt Lewis Helf, Ph.D. > Ecologist > EEO Counselor > National Park Service > Cumberland Piedmont Network > P.O. Box 8 > Mammoth Cave, KY 42259 > Ph: 270-758-2163 > Lab: 270-758-2151 > Fax: 270-758-2609 > **************************************************************** > Science, in constantly seeking real explanations, reveals the true majesty > of our world in all its complexity. > -Richard Dawkins > > The scientific tradition is distinguished from the pre-scientific tradition > in having two layers. Like the latter it passes on its theories but it > also passes on a critical attitude towards them. The theories are passed > on not as dogmas but rather with the challenge to discuss them and improve > upon them. > -Karl Popper > > ...consider yourself a guest in the home of other creatures as significant > as yourself. > -Wayside at Wilderness Threshold in McKittrick Canyon, Guadalupe Mountains > National Park, TX > > Cumberland Piedmont Network (CUPN) Homepage: > http://tiny.cc/e7cdx > > CUPN Forest Pest Monitoring Website: > http://bit.ly/9rhUZQ > > CUPN Cave Cricket Monitoring Website: > http://tiny.cc/ntcql > > CUPN Cave Aquatic Biota Monitoring Website: > http://tiny.cc/n2z1o > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
On 18-Oct-10 14:58:05, Kurt_Helf at nps.gov wrote:> Greetings > I want to remove numbers from a string of characters that > identify sites so that I can merge two data frames. > For example, a site in one frame is called > "001a Frozen Niagara Entrance" whereas the same site > in the other data frame is called "Frozen Niagara Entrance". > It seems to me the easiest thing to do would be to remove > the numbers from the first data frame so the two will match. > How do I go about removing those numbers? > Thanks in advance. > Cheers > KurtTry something based on: X <- "001a Frozen Niagara Entrance" sub("[[:alnum:]]* ","",X) # [1] "Frozen Niagara Entrance" Hoping this helps! Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at wlandres.net> Fax-to-email: +44 (0)870 094 0861 Date: 18-Oct-10 Time: 16:19:08 ------------------------------ XFMail ------------------------------
On 18-Oct-10 15:03:22, Henrique Dallazuanna wrote:> See agrep function: > > agrep("Frozen Niagara Entrance", "001a Frozen Niagara Entrance") > 0 > > To remove the numbers: > > gsub("\\d", "", "001a Frozen Niagara Entrance")That results in "a Frozen Niagara Entrance", which is not what he said he wants (his "numbers" are not purely digital)! You need sub() and "[:[alnum:]]* " as I suggested previously. Also "\\w* " would work, since this "\\w" is equivalent to "[[:alnum:]]": sub("[[:alnum:]]* ", "", "001a Frozen Niagara Entrance") # [1] "Frozen Niagara Entrance" sub("\\w* ", "", "001a Frozen Niagara Entrance") # [1] "Frozen Niagara Entrance"> On Mon, Oct 18, 2010 at 12:58 PM, <Kurt_Helf at nps.gov> wrote: >> Greetings >> I want to remove numbers from a string of characters that >> identify sites so that I can merge two data frames. For example, >> a site in one frame is called "001a Frozen Niagara Entrance" >> whereas the same site in the other data frame is called >> "Frozen Niagara Entrance". It seems to me the easiest thing >> to do would be to remove the numbers from the first data >> frame so the two will match. How do I go about removing those >> numbers? >> Thanks in advance. >> Cheers >> Kurt-------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding at wlandres.net> Fax-to-email: +44 (0)870 094 0861 Date: 18-Oct-10 Time: 16:31:20 ------------------------------ XFMail ------------------------------