[R] if else condition - help
Martin Maechler
maechler at stat.math.ethz.ch
Mon May 23 09:46:43 CEST 2016
>>>>> 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
More information about the R-help
mailing list