[R] write a function inside the summation in a more condensed form
mahmoudfarid30 at yahoo.com
mahmoudfarid30 at yahoo.com
Fri Apr 8 15:54:46 CEST 2016
Dear R Experts
that's my original equation
> x=c(2,4)
> Y1=sum(sapply(1:2,function(i){sum(sapply(1:i,function(j){(3^(x[i]+x[j]))}))}))
> y1
[1] 7371
I want to write the inside function (3^(x[i]+x[j])) in a more condensed form cause this will help me when the multiple summations are more than two
I've tried the following form
> y2=sum(sapply(1:2,function(i){sum(sapply(1:i,function(j){(3^(sum(sapply(i:j,function(l){x[l]}))))}))}))
> y2
[1] 819
But it didn't work, it gave another solution
Any help or recommendations
More information about the R-help
mailing list