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

Rich FitzJohn rich.fitzjohn at gmail.com
Sun Apr 3 06:10:23 CEST 2005


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 at 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 at 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 at 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
>




More information about the R-help mailing list