Skip to content
Prev 52649 / 63424 Next

ifelse() woes ... can we agree on a ifelse2() ?

That is indeed (almost) the documented behaviour. The documented behaviour is slightly more complex; '... returns a value _of the same shape_ as 'test''. IN principle, test can be a matrix, for example.
I took a look. The idea leaves (at least) me very uneasy. If you are recycling 'test' as well as arbitrary-length yes and no, results will become frighteningly hard to predict except in very simple cases where you have well-defined and consistent regularities in the data. And where you do, surely passing ifelse a vetor of the right length, generated by rep() applied to a short 'test' vector, will do what you want without messing around with new functions that hide what you're doing.

Do you really have a case where 'test' is neither a single logical (that could be used with 'if') nor a vector that can be readily replicated to the desired length with 'rep'?

If not, I'd drop the attempt to generate new ifelse-like functions. 

S Ellison



*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}