vendredi 4 mars 2016

Inexplicable error with "if" function: "missing value where TRUE/FALSE needed"

I am running the following "for loop" on my data to exclude listwise all data where father is no longer alive:

for(i in seq_along(survey_data$father_alive)){
if(survey_data$father_alive[i]=="No"){
survey_data <- survey_data[-i, ]
 }
}

When I run the function, I get the following error:

Error in if (survey_data$father_alive[i] == "No") { : 
  missing value where TRUE/FALSE needed

Now take note that the function IS working! It yields the desired result. But I'm worried about the error.

I thought this may be occurring because there is no "else if" function, but this did not solve the problem. There are also no NAs in the column of data being used.

Does anyone have any ideas on what the problem could be?

Aucun commentaire:

Enregistrer un commentaire