[R] Comparison Operator

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Fri May 30 01:23:02 CEST 2003



mhoward at micron.com wrote:
> Does R have a comparison operator similar to the Like function, for example:
> 
> a<-"Is a Fish"
> b<-"Fish"
> 
> if(b in a){c<-TRUE}
> 

How about ?regexpr:

R> a="is a fish"
R> b="fish"
R> regexpr(b,a)
[1] 6
attr(,"match.length")
[1] 4
R> regexpr(b,a)>0
[1] TRUE
R> b="Fish"
R> regexpr(b,a)>0
[1] FALSE

Note
Regards,
Sundar




More information about the R-help mailing list