jeudi 16 avril 2020

R: ifelse turns numeric(0) into NA

Can someone explain to me why the following happens?

ifelse(TRUE, numeric(0), 1)
> [1] NA

I would expect numeric(0) of course. I suspect that this is because ifelse is vectorized, e.g. the following works, but I don't understand exactly what is going on.

if (TRUE) numeric(0) else 1
#> numeric(0)

Aucun commentaire:

Enregistrer un commentaire