[R] vectoring a simple for

Ray Brownrigg ray at mcs.vuw.ac.nz
Mon Nov 25 22:53:20 CET 2002


> Supose that I have a vector beta <- c(1,2,3)
> I need a vector which indice i be beta[i]*sum(beta[-i])
> For example,
> result <- rep(0,3)
> for(i in 1:3) result[i] <- beta[i]*sum(beta[-i])
> result
> [1] 5 8 9
> How I do it with no for?
> 
How about:
beta*(sum(beta) - beta)
?

Hope this helps,
Ray Brownrigg <ray at mcs.vuw.ac.nz>	http://www.mcs.vuw.ac.nz/~ray
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list