Skip to content

I know this is wrong, but why?

1 message · Bill Venables

#
Others have already replied to this pointing out that if ... else ... is a
control statement whereas ifelse(...) is the vectorized function.

Just a minor follow-up point.  The way I would do this calculation is as
follows:

imprv1 <- ifelse(effects0[, 3]*effects1[, 3] > 0,
		  sign(effects0[, 3]) * (effects1[, 3] - effects0[, 3]), 
		  NA)

I'm not suggesting that your way is any less efficient, but this way does
illustrate vectorization  a bit more explicitly as well as the "whole
object" view in a way which maximally contrasts with the SAS "line by line"
view.

Bill Venables.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._