[R] else if statement error

Gabor Grothendieck ggrothendieck at gmail.com
Tue Oct 6 15:57:45 CEST 2009

2009/10/6 Uwe Ligges <ligges at statistik.tu-dortmund.de>:
> The first rule is easy: As long as you are using scalar valued (i.e. length
> 1 vectors in R) "cond", you should prefer
>  if(cond) cons.expr  else  alt.expr
> rather than
>  ifelse(cond, yes, no)
> because the latter one evaluates both "yes" and "no" while the former one
> evaluates exactly one of both expressions.

I don't think that that is true.  The false leg was not evaluated here:

> ifelse(TRUE, { cat("a"); 1}, {cat("b"); 2})
a[1] 1

More information about the R-help mailing list