if-else vs ifelse with lists

后端 未结 3 2278
旧时难觅i
旧时难觅i 2020-11-28 15:19

Why do the if-else construct and the function ifelse() behave differently?

mylist <- list(list(a=1, b=2), list(x=10, y=20))

l1 <- ifelse(sum(sapply(my         


        
3条回答
  •  执念已碎
    2020-11-28 15:43

    For some reason this is marked as a duplicate of Why does ifelse() return single-value output?

    So a work around for that question is:

    a=3
    yo <- ifelse(a==1, 1, list(c(1,2)))
    yo[[1]]
    

提交回复
热议问题