mercredi 19 octobre 2016

When i use is.na in R, vector is returning NA instead of FALSE

I want to create a new variable using ifelse and is.na. But the problem is that this ifelse is only returning 1 and NA. The problems seems to be in my first ifelse, since I run inside ifelse one by one, and only the first is returning NA. I can't understand why, because the code of the 3 ifelse seems to be similar. Does anyone know?

eassociacao<-ifelse((!is.na(dados$CENTRAL)|dados$CENTRAL!=" ") & (!is.na(dados$SISTEMA)|dados$SISTEMA!=" "),1, ifelse((!is.na(dados$CENTRAL)|dados$CENTRAL!=" ") & (is.na(dados$SISTEMA)|dados$SISTEMA==" "),2,3) )

Aucun commentaire:

Enregistrer un commentaire