vendredi 26 décembre 2014

Nested If statements in R

I have a function in R that evaluates several if statements within an if statement. It's returning an error message when I run it (I'm only including the sketh of the code, because the actual function is quite big):



if (X_star - x != 0){
if (w == 1){
#stuff
} else {
#stuff
if (X_star == 1){
#Stuff
} else {
#Stuff
}
#Stuff
}
Y = something
if (Y == 1){
#Stuff
} else {
#Stuff
}
} else {
if (Xmax - x !=0){
Y = something else
if (Y == 1){
#Stuff
} else {
#Stuff
}
} else {
#Stuff
}
}


Error in if (X_star - x != 0) { : missing value where TRUE/FALSE needed.


I read some other posts where people seemed to have the same problem, but I couldn't find a definitive answer. I've stared at it for some time but can't find what is wrong with it. This function is located within a for loop, so I can't really use the vectorized ifelse. I'd appreciate any help.


Cheers,


Napo


Aucun commentaire:

Enregistrer un commentaire