Skip to content

Error: missing value where TRUE/FALSE needed

3 messages · SHASHI SETH, Ulrik Stervbo, John Fox

#
Hi, 



I am getting the following error:

Error in if ((sum > 0 && sums1 > 0 && sums2 > 0) != NA) { : 

missing value where TRUE/FALSE needed





I have including my code below for your review:



fitness_1_data
#
Dear Shashi,

I don't see any code, but I will take a guess anyway:

The error tells you that you try to compare a boolean with something that
is not (TRUE or FALSE cannot be compared to NA).

HTH
Ulrik
On Thu, 9 Jun 2016 at 08:55 SHASHI SETH <sethshashi at rediffmail.com> wrote:

            

  
  
#
Dear Shashi Seth,

The principal problem here is that the "argument" to if() must be logical, while comparing anything to NA always produces NA. The proper way to test for NA is with is.na(). 

There's potentially something more subtle going on here, however, which is that even if some of the elements of the logical expression in the "call" to if() are NA, the expression may evaluate to FALSE (but never to TRUE) if the non-NA elements imply that it is FALSE. Consider the following examples:
[1] FALSE
[1] NA
[1] NA
[1] NA
[1] FALSE
[1] TRUE

I hope that this helps,
 John

-----------------------------
John Fox, Professor
McMaster University
Hamilton, Ontario
Canada L8S 4M4
Web: socserv.mcmaster.ca/jfox