lundi 22 février 2016

R else, else if, else statement

I am getting an error returned when calling a simple function. ANy help greatly appreciated!

Called using.. PlotSummary<-Summary.GY(TREE)

This function in turn calls... tree$SPtype=as.vector(mapply(SPP.func,tree$SP)[1,]) Error: Error in if (SPP == "AB") { : missing value where TRUE/FALSE needed

I really see no issue with syntax - all curly bracket accounted for I believe;

SPP.func=function(SPP)
{  
  if(SPP=='AB'){ 
    SPtype='HW'
    } else if(SPP=='AS'){ 
    SPtype='HW'

  } else if(SPP=='BA'){ 
    SPtype='HW'

  } else if(SPP=='BC'){ 
    SPtype='HW'

  } else if(SPP=='BF'){ 
    SPtype='SW'
     } else if(SPP=='BP'){ 
    SPtype='HW'
    } else if(SPP=='BS'){ 
    SPtype='SW'
   } else if(SPP=='BT'){ 
    SPtype='HW'
    } else if(SPP=='EC'){ 
    SPtype='HW'
    } else if(SPP=='EH'){ 
    SPtype='SW'
    } else if(SPP=='GA'){ 
    SPtype='HW'
     } else if(SPP=='GB'){ 
    SPtype='HW'
    } else if(SPP=='HH'){ 
    SPtype='HW'
    } else if(SPP=='JP'){ 
    SPtype='SW'

  } else if(SPP=='NS'){ 
    SPtype='SW'
   } else if(SPP=='OH'){ 
    SPtype='HW'
    } else if(SPP=='OS'){ 
    SPtype='SW'
   } else if(SPP=='PB'){ 
    SPtype='SW'
   } else if(SPP=='PC' | SPP=='PR'){ 
    SPtype='HW'
     } else if(SPP=='QA'){
    SPtype='HW'
     } else if(SPP=='RB'){ 
    SPtype='HW'
    } else if(SPP=='RM'){ 
    SPtype='HW'
     } else if(SPP=='RP' | SPP=='RN'){ 
    SPtype='SW'
   } else if(SPP=='RO'){ 
    SPtype='HW'
  } else if(SPP=='RS'){ 
    SPtype='SW'
     } else if(SPP=='SB'){ 
    SPtype='HW'
     } else if(SPP=='SM'){ 
    SPtype='HW'
    } else if(SPP=='ST'){
    SPtype='HW'
  } else if(SPP=='TA'){ 
    SPtype='SW'
   } else if(SPP=='WA'){ 
    SPtype='HW'
  } else if(SPP=='WC'){ 
    SPtype='SW'
  } else if(SPP=='WP'){ 
    SPtype='SW'
  } else if(SPP=='WS'){ 
    SPtype='SW'
  } else if(SPP=='YB'){ 
    SPtype='HW'
  } else {
    SPtype='HW'
  }    
  return(c(SPtype=SPtype))
}

Aucun commentaire:

Enregistrer un commentaire