[R] simple q: returning a logical vector of substring matches

Gabor Grothendieck ggrothendieck at gmail.com
Sat Jan 20 20:32:18 CET 2007


Using the builtin month.abb try this:

  regexpr("ov", month.abb) > 0

Although not needed here, if "ov" were a character string that could have
special characters such as . and * that have special meaning in a regular
expression then do this to prevent such interpretation:

  regexpr("ov", month.abb, fixed = TRUE) > 0

See ?regexpr


On 1/20/07, lindeman at bard.edu <lindeman at bard.edu> wrote:
> I'm a relative R novice, and sometimes the simple things trip me up.
>
> Suppose I have
>
> a <- c("apple", "pear")
>
> and I want a logical vector of whether each of these strings contains
> "ear" (in this case, F T). What is the idiom?
>
> Quizzically,
> Mark Lindeman
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list