ifelse与NA是否总是评估为NA?

时间:2019-03-04 16:45:42

标签: r if-statement

虽然之前在这里讨论过opacityNAs,但我想了解这个问题的特定细节,而这个细节之前还没有解决。

可复制的示例:

ifelse

为什么transflag <- c("YES", "YES", "NO", "NO", "NO", "NO", "YES", "YES", "NO") class <- c("SC", "IC", "IC", "SC", NA, "IC", "IC", NA, NA) prod <- c("P1", "P2", NA, "P1", "P2", "P1", NA, "P2", "P1") data <- data.frame(class, prod, transflag) data$transflag <- as.character(data$transflag ) data$class <- as.character(data$class ) data$prod <- as.character(data$prod ) data$transflag4 <- ifelse(data$prod == "P1" & data$class == "SC" , "NO", data$transflag) data$transflag5 <- ifelse(data$prod == "P2" & data$class == "SC" , "NO", data$transflag) 中的结果是NA,而定义了transflag4中的结果呢?考虑到其他发布者提到transflag5对任何事物的评估为NArecode variables with NAs with ifelse() in R),这很奇怪

0 个答案:

没有答案