Re: [R] pattern search

From: Benilton Carvalho <bcarvalh_at_jhsph.edu>
Date: Wed 04 Apr 2007 - 15:27:02 GMT

how about:

length(gregexpr("the", Text)[[1]])

?

b

On Apr 4, 2007, at 10:49 AM, Schmitt, Corinna wrote:

> Dear R-experts,
>
> I'm looking for an easy possibility for pattern search. I have got a
> string and a special pattern. I would like to know if the pattern
> appears in the string, if yes where does it appear (position) and the
> number of appearance.
>
> Example:
>
> Text = c("If the sun shines, no clouds should be seen in the sky!")
> SearchPattern = c("the")
> NumberOfAppearance = 0
> NumberOfLetters = 0
>
> --> NumberOfAppearance should be 2 in the end
>
> How can I get the string length (=number of letters stored in Text)?
>
> Has anyone a good idea?
>
> Thanks, Corinna
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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. Received on Thu Apr 05 01:51:50 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 04 Apr 2007 - 16:30:56 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.