Try this: mapply(function(x, f)f(x), split(t, t %% 2), list(g, f))
On Tue, Mar 1, 2011 at 4:19 PM, ivo welch <ivo...@gmail.com> wrote: > dear R experts--- > > t <- 1:30 > f <- function(t) { cat("f for", t, "\n"); return(2*t) } > g <- function(t) { cat("g for", t, "\n"); return(3*t) } > s <- ifelse( t%%2==0, g(t), f(t)) > > shows that the ifelse function actually evaluates both f() and g() for > all values first, and presumably then just picks left or right results > based on t%%2. uggh... wouldn't it make more sense to evaluate only > the relevant parts of each vector and then reassemble them? > > /iaw > ---- > Ivo Welch > > ______________________________________________ > R-help@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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
______________________________________________ R-help@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.