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}
Michael R Howard
Micron Technology Inc. Boise ID.
Fab C Engineering Software (FCES)
Software Engineer
Comparison Operator
5 messages · mhoward@micron.com, Sundar Dorai-Raj, Spencer Graves +2 more
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
Have you considered "regexpr"? > a<-"Is a Fish" > b<-"Fish" > regexpr(b, a) [1] 6 attr(,"match.length") [1] 4 hth. spencer graves
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}
Michael R Howard
Micron Technology Inc. Boise ID.
Fab C Engineering Software (FCES)
Software Engineer
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
On Thu, May 29, 2003 at 05:11:24PM -0600, 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}
You probably want grep:
a<-"Is a Fish" b<-"Fish" if (grep(b,a)) c<-TRUE c
[1] TRUE Hth, Dirk
Don't drink and derive. Alcohol and analysis don't mix.
grep() by itself isn't quite right for this job:
a<-"Is a Fish" b<-"aFish" if (grep(b,a)) c<-TRUE
Error in if (grep(b, a)) c <- TRUE : argument is of length zero -Don
At 6:24 PM -0500 5/29/03, Dirk Eddelbuettel wrote:
On Thu, May 29, 2003 at 05:11:24PM -0600, 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}
You probably want grep:
> a<-"Is a Fish" b<-"Fish" if (grep(b,a)) c<-TRUE > c
[1] TRUE Hth, Dirk -- Don't drink and derive. Alcohol and analysis don't mix.
______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
-------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA