[R] how can I do this sum?

Roland Rau roland.rproject at gmail.com
Mon Aug 11 23:23:48 CEST 2008


dott wrote:
> Hi,
> 
> Suppose I have a vector in real number
> (x1, x2, x3, x4, x5, x6)
> 
> My question is how I can get  
> x5*x3*x1 + x6*x4*x2 ?
> 
> Thanks a lot.
> Dot.

hard to say what you mean?
Maybe summing up all elements in odd positions and the ones in even 
positions?

myvector <- 1:6

1*3*5 + 2*4*6
sum(prod(myvector[((1:length(myvector))%%2)==1]),prod(myvector[((1:length(myvector))%%2)==0])) 



Best,
Roland



More information about the R-help mailing list