On Sat, 2007-01-20 at 13:30 -0500, [EMAIL PROTECTED] 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
See ?grep and ?regexp
a <- c("apple", "pear")
> grep("ear", a)
[1] 2
> grep("ear", a, value = TRUE)
[1] "pear"
If you actually want the answer to be FALSE TRUE, then:
> a %in% grep("ear", a, value = TRUE)
[1] FALSE TRUE
In that case see ?"%in%"
HTH,
Marc Schwartz
______________________________________________
[email protected] 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.