"missing value where TRUE/FALSE needed" error in GA package
<p>When running a genetic algorithm using the GA package, I am receiving a "missing value where TRUE/FALSE needed" error. In my code below, <code>like</code> is a function for fitness and <code>X</code> is a numeric vector of length 6.</p>

<pre><code>library(GA)
y&lt;-c(46,38,49,55)
W&lt;-matrix(c(0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0),ncol=4)
ei&lt;-eigen(W)$values
data&lt;- matrix(c(14691,14150,14607,15140,5337,5386,5207,5178),ncol=2)
         like=function(x)
            {
              co&lt;-c(x[2],x[3])  
              e&lt;-x[4]*W%*%y-data%*%co-x[1]
              L&lt;-30*log(2)-15*log(2*pi)+log(prod(1-x[4]*Re(ei)))-15*log(x[5])+sum(log(pnorm(-x[6]*e/sqrt(x[5]))))
              -0.5/x[5]*t(e)%*%e
              return(L)
            }
    GA &lt;- ga(type = "real-valued", 
             fitness =  like,
             min=c(-100,0,-50,-10,0.001,0),
             max=c(100,100,0,10,100,10),
             popSize = 100, maxiter = 200,
             optim = TRUE)
</code></pre>

<p>The result and error are as below:</p>

<pre><code>GA | iter = 1 
Mean =      -Inf | Best = -2.870387 
Error in if (fmin &gt; (sfactor * fave - fmax)/(sfactor - 1)) { : 
  missing value where TRUE/FALSE needed
</code></pre>