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

Christos Hatzis christos at nuverabio.com
Sat Jan 20 19:58:51 CET 2007

You can try the following:

 a == grep("ear", a, value=T)


Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of lindeman at bard.edu
Sent: Saturday, January 20, 2007 1:31 PM
To: r-help at stat.math.ethz.ch
Subject: [R] simple q: returning a logical vector of substring matches

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?

Mark Lindeman

R-help at stat.math.ethz.ch mailing list
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