Re: [R] is there a function like %in% for characters?

From: Sundar Dorai-Raj <sundar.dorai-raj_at_pdf.com>
Date: Mon 04 Apr 2005 - 04:07:21 EST

Terry Mu wrote on 4/2/2005 9:38 PM:
> like:
>
> "a" %in% "abcd"
> TRUE
>
> Thanks.
>

See ?regexpr.

regexpr("a", "abcd") > 0

However, the first argument is not vectorized so you may also need something like:

 > sapply(c("a", "b", "e"), regexpr, c("abcd", "bcde")) > 0

          a b e
[1,] TRUE TRUE FALSE

[2,] FALSE TRUE TRUE Be sure to read up on regular expressions if pursuing this option.

HTH, --sundar



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 Received on Mon Apr 04 04:13:38 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:01 EST