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? Thanks in advance. =======================================Cezar Freitas (ICQ 109128967) IMECC - UNICAMP Campinas, SP - Brasil -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 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> mcs.vuw.ac.nz/~ray -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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, 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 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._