【发布时间】:2021-01-28 08:27:38
【问题描述】:
谁能解释一下我做错了什么。我不了解 R 中 ifelse 函数的行为。我希望 ifelse 函数会返回整个列表 ids_match。但是,这些是我在控制台窗口中使用 RStudio 版本 1.3.1093 得到的结果:
cond1 = FALSE
cond2 = FALSE
cond3 = TRUE
ids_match = list(1, 2, 3)
ifelse(cond1 & cond2 & cond3, ids_match[1], ids_match)
[[1]] [1] 1
ifelse(TRUE, ids_match[1], ids_match)
[[1]] [1] 1
ifelse(FALSE, ids_match[1], ids_match)
[[1]] [1] 1
ifelse(FALSE, "TRUE", "FALSE")
[1]“假”
ifelse(TRUE, "TRUE", "FALSE")
[1]“真”`
【问题讨论】:
标签: function if-statement