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

From: Rich FitzJohn <rich.fitzjohn_at_gmail.com>
Date: Sun 03 Apr 2005 - 14:10:23 EST

Or, using the %foo%-style functions:

"%charin%" <- function(x, y) regexpr(x, y) != -1

> "a" %charin% "asdf"

[1] TRUE
> "a" %charin% "bsdf"

[1] FALSE Cheers,
Rich

On Sat, 2 Apr 2005 22:54:35 -0500, "Liaw, Andy" <andy_liaw@merck.com> wrote:
> I suppose here's one way:
>
> > hasChar <- function(x, y) { length(grep(x, y)) > 0 }
> > hasChar("a", "abcd")
> [1] TRUE
> > hasChar("e", "abcd")
> [1] FALSE
>
> Andy
>
> > From: Terry Mu
> >
> > like:
> >
> > "a" %in% "abcd"
> > TRUE
> >
> > Thanks.
> >
> > ______________________________________________
> > 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
> >
> >
> >
>
> ______________________________________________
> 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
>



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 Sun Apr 03 14:24:09 2005

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