[R] vectoring a simple for

Cezar Augusto de Freitas Anselmo cafa at ime.unicamp.br
Mon Nov 25 22:05:28 CET 2002

Hi all. A simple question.

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])
[1] 5 8 9
How I do it with no for?
Thanks in advance.

Cezar Freitas (ICQ 109128967)
Campinas, SP - Brasil

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