Skip to content
Back to formatted view

Raw Message

Message-ID: <17791.55566.562687.131@stat.math.ethz.ch>
Date: 2006-12-13T10:42:22Z
From: Martin Maechler
Subject: ifelse misusage become more and more frequent...
In-Reply-To: <457F1E11.4020304@freesurf.Fr>

>>>>> "jropers at freesurf" == jropers at freesurf fr <jropers at freesurf.Fr>
>>>>>     on Tue, 12 Dec 2006 22:24:33 +0100 writes:

    jropers at freesurf> ...ifelse, a function of three **vector**
    jropers at freesurf> arguments....  Yes !!  I misunderstood the
    jropers at freesurf> functioning of ifelse.  

Seems to happen more an more often.
When I teach "R programming" I nowadays usually emphasize that people
should often *NOT* use ifelse().
In other words, I think ifelse() is much over-used in situations
where something else would be both clearer and more efficient.

Is there a document / book around which lures people into
misusing ifelse() so frequently?

Martin Maechler, ETH Zurich

    jropers at freesurf> Peter Dalgaard wrote:
    >> jropers at freesurf.fr wrote:
    >>> What is puzzling me is that rnorm(1) is only evaluated
    >>> *twice*, one time for each branch, with only 2 different
    >>> random deviates, instead of giving ten different random
    >>> deviates. y1 has indeed 10 values but with only 2
    >>> different ones.
    >>> 
    >> I find it more puzzling why you expect that ifelse, a
    >> function of three vector arguments, would cause its input
    >> arguments to be reevaluated for every element of the
    >> result.