r - 为什么 ifelse 和 if 语句不一样?
问题描述
给定数据:
condition <- rep(TRUE, 10)
varExist <- c(FALSE, rep(TRUE, 9))
cond <- list(c(rep(TRUE, 6) ,rep(FALSE, 4)))
有条件时:
condition <- if(varExist[1]){
condition
}else{
condition & !cond[[1]]
}
然后我想将if
语句转换为ifelse
语句:
condition <- ifelse(varExist[1], condition, condition & !cond[[1]])
但结果不同:预期:
> condition
[1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE
但是还有:
> condition
[1] FALSE
解决方案
推荐阅读
- python - 如何替换文件中的单词/数字
- express - nuxt serverMiddleware 中的 Express Nodemailer - 错误:spawn /usr/sbin/sendmail ENOENT
- sql - Webform 到 SQL 数据库 - 如何传递 user.identity.name?
- asp.net - 如何在 Sublime Text 3 中实现 ASP?
- python - 索引超出范围(即使我设置了最大值)
- android - Android - 单击按钮时转到文本视图中的上标
- logging - 停止 jmeter.log 注销第三方日志
- linux - 由于缺乏地址检查,带有 O_DIRECT 的 IO 是否安全?
- flutter - Flutter: Pageview builder : 有效地激活和停用监听器
- atlassian-sourcetree - 单击重置分支到当前提交并丢失了我所有的工作,我到底做了什么?