Re: [R] inefficient ifelse() ?

From: Thomas Lumley <tlumley_at_uw.edu>
Date: Wed, 02 Mar 2011 10:59:27 +1300

On Wed, Mar 2, 2011 at 9:36 AM, ivo welch <ivo.welch_at_gmail.com> wrote:
> thanks, Henrique.  did you mean
>
>    as.vector(t(mapply(function(x, f)f(x), split(t, ((t %% 2)==0)),
> list(f, g))))   ?
>
> otherwise, you get a matrix.
>
> its a good solution, but unfortunately I don't think this can be used
> to redefine ifelse(cond,ift,iff) in a way that is transparent.  the
> ift and iff functions will always be evaluated before the function
> call happens, even with lazy evaluation.  :-(
>
> I still think that it makes sense to have a smarter vectorized %if% in
> a vectorized language like R.  just my 5 cents.
>

Ivo,

There is no guarantee in general that f(x[3,5,7]) is the same as f(x)[3,5,7]

      -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 01 Mar 2011 - 22:23:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Mar 2011 - 22:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive