[R] double summation

David Winsemius dwinsemius at comcast.net
Thu Oct 15 06:05:21 CEST 2015


On Oct 14, 2015, at 1:29 PM, Sherouk Moawad via R-help wrote:

> Σi=02 Σj=01(exp(xi+xj)), i>j if (i>0 and j>0)   I want to write this summation which has a condition on numerator(j<i)i>0 and j>0I tried on this code

That comes across as only barely comprehensible.


> sum(sapply(0:2, function(i){sum(sapply(0:1, function(j){if (i>0&j>0){i>j}{exp(x[i]+x[j])}))}))But it didn't work Any help please
> 	[[alternative HTML version deleted]]

You should learn to post in plain text. This IS a plain text mailing list.

It is generally effective to include Boolean logic in the summand. Try this untested modification:

sum(
    sapply(0:2, function(i){ sum( 
                sapply(0:1, function(j){ (i>0)*(j>0)(i>j)*(exp(x[i]+x[j]) ))))
      )

-- 
David Winsemius
Alameda, CA, USA



More information about the R-help mailing list