[R] summation coding

Rainer Schuermann rainer.schuermann at gmx.net
Fri Oct 19 09:50:52 CEST 2012

```You asked for a loop, you got one...

Vectorized is easier and faster:
x\$c <- x\$a * ( sum( x\$b ) - x\$b )

Rgds,
Rainer

On Friday 19 October 2012 09:38:35 you wrote:
> Hi,
>
> I think I solved it myself by writing loops.
>
> What I meant is: are there in-built functions in R that calculate the
> following:
>
> a1(b2+...+b190) + a2(b1+b3+...+b190) + ...
>
> I managed to solve it, quite similar to what you just emailed.
>
> Thanks!
>
> On 19 October 2012 09:20, Rainer Schuermann <rainer.schuermann at gmx.net>wrote:
>
> > Is it possible that you mean
> > a1(b2+b3+b4) + a2(b1+b3+b4) + a3(b1+b2+b4) + a4(b1+b2+b3)
> >     ^  ^  ^
> >
> >
> > On Thursday 18 October 2012 12:33:39 djbanana wrote:
> > > I would like to code the following in R: a1(b1+b2+b3) + a2(b1+b3+b4) +
> > > a3(b1+b2+b4) + a4(b1+b2+b3)
> > >
> > > or in summation notation: sum_{i=1, j\neq i}^{4} a_i * b_i
> > >
> > > I realise this is the same as: sum_{i=1, j=1}^{4} a_i * b_i - sum_{i=j}
> > a_i
> > > * b_i
> > >
> > > would appreciate some help.
> > >
> > > Thank you.
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > http://r.789695.n4.nabble.com/summation-coding-tp4646678.html
> > > Sent from the R help mailing list archive at Nabble.com.
> > >
> > > ______________________________________________
> > > R-help at r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help