[R] integer(0) and NA do not equal FALSE

Gray Calhoun gray.calhoun at gmail.com
Sun Dec 20 03:17:44 CET 2009


Hi Jonathan,
  The function "isTRUE" is useful for this sort of thing:
isTRUE(pmatch("hi", "hop")) evaluates to FALSE.
--Gray

On Sat, Dec 19, 2009 at 12:47 PM, Jonathan <jonsleepy at 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 at 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.
>



-- 
Gray Calhoun

Assistant Professor of Economics
Iowa State University




More information about the R-help mailing list