[R] vectoring a simple for

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Mon Nov 25 23:10:46 CET 2002


On Mon, 25 Nov 2002, Cezar Augusto de Freitas Anselmo wrote:

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

beta * (sum(beta) - beta)

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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