jeudi 28 janvier 2021

Struggling with the ifelse function in R

Can someone please explain me what I am doing wrong. I don't understand the behaviour of the ifelse function in R. These are the results I get in Console Window:

> cond1

[1] FALSE

> cond2

[1] FALSE

> cond3

[1] TRUE

> cond1 & cond2 & cond3

[1] FALSE

> ids_match_

[1] 15 26 65 96 107 122 163 178 193 198 235 244 252 260 268 275 300

> ids_match_[1]

[1] 15

> ifelse(cond1 & cond2 & cond3, ids_match_[1], ids_match_)

[1] 15

> ifelse(TRUE, ids_match_[1], ids_match_)

[1] 15

> ifelse(FALSE, ids_match_[1], ids_match_)

[1] 15

> ifelse(FALSE, "TRUE", "FALSE")

[1] "FALSE"

> ifelse(TRUE, "TRUE", "FALSE")

[1] "TRUE"

Aucun commentaire:

Enregistrer un commentaire