Порядок вложенного оператора ifelse, по-видимому, влияет на оценку условий is.na.
# Create df
Var1 <- c(5,5,5,5)
Var2 <- c(0,0,NA,NA)
tmp.1 <- data.frame(Var1, Var2)
# Why is it not possible to evaluate NA in the second nested ifelse statement?
tmp.1$Var2 <- ifelse(tmp.1$Var1 == 5 & tmp.1$Var2 == 0, 6,
ifelse(tmp.1$Var1 == 5 & is.na(tmp.1$Var2), 7, tmp.1$Var2))
# Yet it works when the same ifelse statement comes first.
tmp.1$Var2 <- ifelse(tmp.1$Var1 == 5 & is.na(tmp.1$Var2), 7,
ifelse(tmp.1$Var1 == 5 & tmp.1$Var2 == 0, 6, tmp.1$Var2))
Есть ли здесь логика c или это ошибка?