[R] how can I do this sum?
Rolf Turner
r.turner at auckland.ac.nz
Mon Aug 11 23:18:44 CEST 2008
On 12/08/2008, at 7:09 AM, 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 ?
v <- c(x1, x2, x3, x4, x5, x6)
m <- matrix(v,ncol=3)
sum(apply(m,1,prod))
This could easily be ``generalized'' and bundled up in a function if
so desired.
cheers,
Rolf Turner
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
More information about the R-help
mailing list