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

From: jim holtman <jholtman_at_gmail.com>
Date: Sat 20 Jan 2007 - 18:59:24 GMT

try 'regexpr'

> a <- c("apple", "pear")
> regexpr('ear',a)!=-1

[1] FALSE TRUE
>

On 1/20/07, lindeman@bard.edu <lindeman@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@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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
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 Sun Jan 21 06:18:30 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 Sat 20 Jan 2007 - 19:31:26 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.