If the input is "gdfsa-sdhchc99-88" then assuming you only want "88" but not "99" then if s is the vector of words that we already computed:
s[regexpr("^[0-9]+", s) > 0] or that could be combined with the strapply solution into one line: > strapply("gdfsa-sdhchc99-88", "\\w+", ~ if (regexpr("^[0-9]*$", x) > 0) > x)[[1]] [1] "88" That picks out words and then tests them as before. On Thu, May 14, 2009 at 2:58 AM, RON70 <ron_michae...@yahoo.com> wrote: > > Thanks for these suggestions. However I have one more question. Is there any > way to extract only numbers? For example I want to extract only "88" in my > example. > > Regards, > > MUHC-Research wrote: >> >> Hi Ron, >> >> Look up the grep() function. >> >> Cheers, >> >> -- >> *Luc Villandré* >> /Biostatistician >> McGill University Health Center - >> Montreal Children's Hospital Research Institute/ >> >> RON70 wrote: >>> Hi all, is there any function to find some words in a character-string? >>> For >>> example suppose the string is : "gdfsa-sdhchc-88", now I want to find >>> whether this string contains "sdhch". Is there any R function to do that? >>> >>> Regards, >>> >> // >> >> ______________________________________________ >> 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. >> >> > > -- > View this message in context: > http://www.nabble.com/Searching-within-a-ch.-string-tp23484010p23535406.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. > ______________________________________________ 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.