mercredi 6 juillet 2016

R doesn't respect my if loop condition

I'm creating a categorical variable given some values. The if loop runs but it doesn't give me any observation with "D", despite it should exist. Do you know what is happening?

Thank you in advance.

data$n_clasif<-"D"
for (i in 1:n){
if (data$forecast[i]>=10000){
data$n_clasif[i]="A"
} else if   (data$forecast[i]<10000 & data$forecast[i]>=2000){
data$n_clasif[i]="B"
} else if (data$forecast[i]<2000 && data$CL_CLASIF_ROLLO[i]!="D"){
data$n_clasif[i]="C"
} else {
data$n_clasif[i]="D"
}
}

Aucun commentaire:

Enregistrer un commentaire