[R] ifelse versus ...

Francisco J Molina FJMolina at lbl.gov
Mon Apr 29 02:27:28 CEST 2002

I read somewhere that, instead of the structure if(...) else(...)
it is better to use the command ifelse(...,...,...).

Currently I am using structures like

ifelse(...,{sequence; of; commands}, 0)

instead of if(...){sequence; of; commands}

and I am using 

ifelse(...,{sequence; of; commands}, {another; Sequence; Of; Commands })

instead of 

if(...){sequence; of; commands}
else{another; Sequence; Of; Commands })

In this way the program becomes a little bit more difficult to read but
I think that I am optimizing the performance.

The question is:

Am I actually optimizing the performance?
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list