Q:

Error in fzero in R missing value where TRUE/FALSE needed

I am trying to find the power values with fzero function in R using myfunction in the following way: 
myfunction = function(delta,data,cv){
if(mean(data^delta)!=0)
y=cv-sd((data^delta),na.rm=TRUE)/mean((data^delta),na.rm=TRUE)
return(y)}
b=repmat(NaN,12,Nest)
for (m in 1:12) {
        if (m==1) 
                indDates=which(is.element(month, c(12, 1, 2)))
        else if (m==12) 
                indDates=which(is.element(month, c(11, 12, 1)))
        else 
                indDates=which(is.element(month, c(m-1, m, m+1)))
        cvO=apply(prO[indDates,],2,sd,na.rm=TRUE)/colMeans(prO[indDates,], na.rm=TRUE)
        for (i in 1:Nest) {
                if (!is.na(cvO[i]))  
                        b[m,i]=fzero(function(x) myfunction(x,abs(prM[indDates,i]),cvO[i]),1)
        }
}

But I get the following error message:
Error in if (fb == 0) return(list(x = b, fval = fb)) : 
  missing value where TRUE/FALSE needed
I do not understand what is the matter and how I should fix it? Could someone please help me?

A:

Finaly, I could solve this matter by the following way:
date=DatevecV(t1) % t1 are time values from netCDF file   
ndata=nrow(prO)
Nest=ncol(prO)
b=repmat(NaN,12,Nest) 
month=unlist(date[2])

varCoeficient = function(delta,data,cv){
y=cv-sd((data^delta),na.rm=TRUE)/mean((data^delta),na.rm=TRUE)
return(y)}

for (m in 1:12) {
         if (m==1) 
                indDates=which(is.element(month, c(12, 1, 2)))
          else if (m==12) 
                  indDates=which(is.element(month, c(11, 12, 1)))
          else 
                 indDates=which(is.element(month, c(m-1, m, m+1)))
          cvO=apply(prO[indDates,],2,sd,na.rm=TRUE)/colMeans(prO[indDates,], na.rm=TRUE)
 for (i in 1:Nest) {
   if (!is.na(cvO[i])) {
     bi <- try(fzero(function(x)
 varCoeficient(x,abs(prM[indDates,i]),cvO[i]),1),silent=T)
     if ("try-error" %in% class(bi)) {  # an error occurred
       b[m,i] <- NA
     } else {
       b[m,i] <- bi$x
     }
   }
 }
 }

