Hi all, Is there any process to conduct a search for a particular digit or letter in a ch. string? For example I want to make a search where 1st numeric figure appears in the string "asd123". Here the answer should be "4" Thanks, -- View this message in context: http://www.nabble.com/Searching-1st-number-within-a-ch.-string-tp25400580p25400580.html Sent from the R help mailing list archive at Nabble.com.
Try this: head(unlist(gregexpr("[0-9]", "asd123")), 1) On Fri, Sep 11, 2009 at 10:02 AM, RON70 <ron_michael70@yahoo.com> wrote:> > Hi all, > > Is there any process to conduct a search for a particular digit or letter > in > a ch. string? For example I want to make a search where 1st numeric figure > appears in the string "asd123". Here the answer should be "4" > > Thanks, > -- > View this message in context: > http://www.nabble.com/Searching-1st-number-within-a-ch.-string-tp25400580p25400580.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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Try this:> regexpr("[0-9]", "asd123")[1] 4 attr(,"match.length") [1] 1 On Fri, Sep 11, 2009 at 9:02 AM, RON70 <ron_michael70 at yahoo.com> wrote:> > Hi all, > > Is there any process to conduct a search for a particular digit or letter in > a ch. string? For example I want to make a search where 1st numeric figure > appears in the string "asd123". Here the answer should be "4" > > Thanks, > -- > View this message in context: http://www.nabble.com/Searching-1st-number-within-a-ch.-string-tp25400580p25400580.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >