为什么ifelse与if语句不同?

时间:2018-10-04 09:08:52

标签: r

给出数据:

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

0 个答案:

没有答案
相关问题