try using 'grepl'

> if( grepl("hi", "hop", fixed = TRUE) ){
+      print('yes, your substring is in your string')
+ } else print('no, your substring is not in your string')
[1] "no, your substring is not in your string"
>


On Sat, Dec 19, 2009 at 3:47 PM, Jonathan <jonsle...@gmail.com> wrote:

> Hi,
>   A noobie question:  I'm simply trying to run a conditional statement that
> evaluates if a substring is found within a larger string.  I find that if
> it
> IS found, my function returns TRUE (great!), but if not, the condition does
> not evaluate to FALSE.
>
> ex):
>
> if( grep("hi", "hop", fixed = TRUE) )
>      print('yes, your substring is in your string')
> else print('no, your substring is not in your string')
>
> alternatively, I could replace grep with pmatch:
>
> if (pmatch('hi','hop'))
>      print('yes, your substring is in your string')
> else print('no, your substring is not in your string')
>
>
> The first example, using grep, returns logical(0).  The second, using
> pmatch, returns NA.  Any idea how to convert either of those to FALSE, or
> else a different function that would do the trick?
>
> Thanks,
> Jon
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to