[R] writing an equation with multiple summation

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Mon Sep 28 18:26:30 CEST 2015


The brute force answer involves for loops or apply functions, with or without defining your own functions for calculating terms. More optimized methods usually require understanding the specific structure of the summations and unwinding them with functions like expand.grid. For more specific help, read the Posting Guide (which among other things warns you to post in plain text) and post a specific example of the type of problem that you want to solve.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On September 28, 2015 8:26:56 AM PDT, Maram SAlem <marammagdysalem at gmail.com> wrote:
>Dear All,
>
>I'm trying to write and evaluate an equation which involves multiple
>summations but can't figure out how to do it.
>
>I've an numeric vector r
>r<-vector(mode = "numeric", length = m)
> and I have multiple summations (for ex.) of the form:
>
>[(sum from r[1]=0 to g(r[1])) (sum from r[2] =0 to g(r[2]))......(sum
>from
>r[m] to g(r[m]))] {the sum is over some complicated expression in
>r[1],r[2],.....,r[m]},
>
>where g(r[i]) = m- (r[1] +r[2]+...+r[i-1])
>Any suggestions for some function or a package that can help me with
>this?
>
>Many Thanks,
>Maram
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list