mercredi 25 novembre 2015

if else statement error R

My code is as follows:

if (as.numeric(income[1,6]) < as.numeric(income[1,5])){
  wotrans<- round(-(as.numeric(income[1,6])/as.numeric(income[1,5]))^(1/5),2)
}
else{
  wotrans<- round((as.numeric(income[1,6])/as.numeric(income[1,5])-1)^(1/5),2)
}

But it keeps throwing this error:

Error in if (as.numeric(income[1, 6]) < as.numeric(income[1, 5])) { : 
  missing value where TRUE/FALSE needed

I dont see how TRUE/FALSE is missing because when i try

as.numeric(income[1,6])<as.numeric(income[1,5])

I get TRUE or FALSE outcomes income[1,6] and income[1,5] are integers in a data.frame

Aucun commentaire:

Enregistrer un commentaire