Skip to content
Back to formatted view

Raw Message

Message-ID: <22338.46435.636940.995371@stat.math.ethz.ch>
Date: 2016-05-23T07:46:43Z
From: Martin Maechler
Subject: if else condition - help
In-Reply-To: <CAAxdm-7VoMoVM+kyw509Zc=1LtH1BTSPNRUCz9ZapEqVx-P9Hw@mail.gmail.com>

>>>>> jim holtman <jholtman at gmail.com>
>>>>>     on Sun, 22 May 2016 16:47:06 -0400 writes:

    > if you want to use 'ifelse', here is a way:

hmm, why should he want that ?
The OP did mention that it's about somewhat large objects, so
efficiency is one of the considerations :

ifelse() is often convenient and nicely self-explaining, but it 
is (because of its generality, but also by its definition)
much *less efficient* than the (sometimes slightly less
convenient) ways you were shown previously in this thread :

- For the generalized case findInterval() is order of magnitudes
  better, and
- for the simple case you were shown to use logical indexing,
  i.e., calls ? la    x[x > k] <- ..


In summary:
   Use  ifelse()  much less -- notably if writing
   functions/code which should scale !


Martin Maechler
ETH Zurich