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.