Hello Jeff, Thanks a lot. I tried it and see that it prints out the entire 100 partial sums, so I can take the last value as the partial sum for the first 100 terms. Would there be any way cumsum can print only the nth partial sum, i.e. the last value in the array, instead of printing the entire array? Thanks again. Joseph On Fri, Jul 24, 2015 at 2:02 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> Please reply-all so the mailing list stays in the loop. > > cumsum(1/(1:100)^2) > > gives you the partial sums up through i=100. > --------------------------------------------------------------------------- > 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 July 24, 2015 10:30:09 AM PDT, Janh Anni <annijanh at gmail.com> wrote: > >Hello Jeff, > > > >Thank you so much for the suggestion, I searched cumsum as suggested > >but > >not sure it is what I had in mind. For instance if I had the infinite > >series: [image: Inline image 1] > > > >and want to compute the sum of the, say, first 100 terms, how could I > >use > >cusum to do that? > > > >Thanks again, > > > >Janh > > > > > >On Thu, Jul 23, 2015 at 11:51 PM, Jeff Newmiller > ><jdnewmil at dcn.davis.ca.us> > >wrote: > > > >> ?cumsum > >> > > >--------------------------------------------------------------------------- > >> 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 July 23, 2015 8:23:39 PM PDT, Janh Anni <annijanh at gmail.com> > >wrote: > >> >Dear All, > >> > > >> >Does anyone know of any R functions that compute partial sums of > >> >series? > >> > > >> >Thanks in advance! > >> > > >> >Janh > >> > > >> > [[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. > >> > >> > >[[alternative HTML version deleted]]
cumsum(1/(1:100)^2)[100]> On Jul 24, 2015, at 4:37 PM, Janh Anni <annijanh at gmail.com> wrote: > > Hello Jeff, > > Thanks a lot. I tried it and see that it prints out the entire 100 partial > sums, so I can take the last value as the partial sum for the first 100 > terms. Would there be any way cumsum can print only the nth partial sum, > i.e. the last value in the array, instead of printing the entire array? > Thanks again. > > Joseph > > On Fri, Jul 24, 2015 at 2:02 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> > wrote: > >> Please reply-all so the mailing list stays in the loop. >> >> cumsum(1/(1:100)^2) >> >> gives you the partial sums up through i=100. >> --------------------------------------------------------------------------- >> 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 July 24, 2015 10:30:09 AM PDT, Janh Anni <annijanh at gmail.com> wrote: >>> Hello Jeff, >>> >>> Thank you so much for the suggestion, I searched cumsum as suggested >>> but >>> not sure it is what I had in mind. For instance if I had the infinite >>> series: [image: Inline image 1] >>> >>> and want to compute the sum of the, say, first 100 terms, how could I >>> use >>> cusum to do that? >>> >>> Thanks again, >>> >>> Janh >>> >>> >>> On Thu, Jul 23, 2015 at 11:51 PM, Jeff Newmiller >>> <jdnewmil at dcn.davis.ca.us> >>> wrote: >>> >>>> ?cumsum >>>> >> >>> --------------------------------------------------------------------------- >>>> 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 July 23, 2015 8:23:39 PM PDT, Janh Anni <annijanh at gmail.com> >>> wrote: >>>>> Dear All, >>>>> >>>>> Does anyone know of any R functions that compute partial sums of >>>>> series? >>>>> >>>>> Thanks in advance! >>>>> >>>>> Janh >>>>> >>>>> [[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. >>>> >>>> >> >> > > [[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.
Janh: It sounds like you really need to go through an R tutorial or two before posting further, as this is a pretty basic query. Or am I wrong about this? An answer: Just use indexing cumsum(1/seq_len(100)^2)[seq(10, to = 100,by = 10)] ## keeps every 10th [1] 1.549768 1.596163 1.612150 1.620244 1.625133 1.628406 1.630750 1.632512 1.633884 [10] 1.634984 But beware FAQ 7.31 for long series. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Fri, Jul 24, 2015 at 4:37 PM, Janh Anni <annijanh at gmail.com> wrote:> Hello Jeff, > > Thanks a lot. I tried it and see that it prints out the entire 100 partial > sums, so I can take the last value as the partial sum for the first 100 > terms. Would there be any way cumsum can print only the nth partial sum, > i.e. the last value in the array, instead of printing the entire array? > Thanks again. > > Joseph > > On Fri, Jul 24, 2015 at 2:02 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> > wrote: > >> Please reply-all so the mailing list stays in the loop. >> >> cumsum(1/(1:100)^2) >> >> gives you the partial sums up through i=100. >> --------------------------------------------------------------------------- >> 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 July 24, 2015 10:30:09 AM PDT, Janh Anni <annijanh at gmail.com> wrote: >> >Hello Jeff, >> > >> >Thank you so much for the suggestion, I searched cumsum as suggested >> >but >> >not sure it is what I had in mind. For instance if I had the infinite >> >series: [image: Inline image 1] >> > >> >and want to compute the sum of the, say, first 100 terms, how could I >> >use >> >cusum to do that? >> > >> >Thanks again, >> > >> >Janh >> > >> > >> >On Thu, Jul 23, 2015 at 11:51 PM, Jeff Newmiller >> ><jdnewmil at dcn.davis.ca.us> >> >wrote: >> > >> >> ?cumsum >> >> >> >> >--------------------------------------------------------------------------- >> >> 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 July 23, 2015 8:23:39 PM PDT, Janh Anni <annijanh at gmail.com> >> >wrote: >> >> >Dear All, >> >> > >> >> >Does anyone know of any R functions that compute partial sums of >> >> >series? >> >> > >> >> >Thanks in advance! >> >> > >> >> >Janh >> >> > >> >> > [[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. >> >> >> >> >> >> > > [[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.
On Jul 24, 2015, at 4:37 PM, Janh Anni wrote:> Hello Jeff, > > Thanks a lot. I tried it and see that it prints out the entire 100 partial > sums, so I can take the last value as the partial sum for the first 100 > terms. Would there be any way cumsum can print only the nth partial sum, > i.e. the last value in the array, instead of printing the entire array? > Thanks again.Wouldn't that just mean using sum instead of cumsum????? Can even check the error from the analytical limit.> sum(1/(1:100)^2) - pi^2/6[1] -0.009950167> > Joseph > > On Fri, Jul 24, 2015 at 2:02 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> > wrote: > >> Please reply-all so the mailing list stays in the loop. >> >> cumsum(1/(1:100)^2) >> >> gives you the partial sums up through i=100. >> --------------------------------------------------------------------------- >> 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 July 24, 2015 10:30:09 AM PDT, Janh Anni <annijanh at gmail.com> wrote: >>> Hello Jeff, >>> >>> Thank you so much for the suggestion, I searched cumsum as suggested >>> but >>> not sure it is what I had in mind. For instance if I had the infinite >>> series: [image: Inline image 1] >>> >>> and want to compute the sum of the, say, first 100 terms, how could I >>> use >>> cusum to do that? >>> >>> Thanks again, >>> >>> Janh >>> >>> >>> On Thu, Jul 23, 2015 at 11:51 PM, Jeff Newmiller >>> <jdnewmil at dcn.davis.ca.us> >>> wrote: >>> >>>> ?cumsum >>>> >> >>> --------------------------------------------------------------------------- >>>> 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 July 23, 2015 8:23:39 PM PDT, Janh Anni <annijanh at gmail.com> >>> wrote: >>>>> Dear All, >>>>> >>>>> Does anyone know of any R functions that compute partial sums of >>>>> series? >>>>> >>>>> Thanks in advance! >>>>> >>>>> Janh >>>>> >>>>> [[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. >>>> >>>> >> >> > > [[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.David Winsemius Alameda, CA, USA
Thanks Bert! On Fri, Jul 24, 2015 at 7:57 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote:> Janh: > > It sounds like you really need to go through an R tutorial or two > before posting further, as this is a pretty basic query. Or am I wrong > about this? > > An answer: Just use indexing > > cumsum(1/seq_len(100)^2)[seq(10, to = 100,by = 10)] ## keeps every 10th > > [1] 1.549768 1.596163 1.612150 1.620244 1.625133 1.628406 1.630750 > 1.632512 1.633884 > [10] 1.634984 > > > But beware FAQ 7.31 for long series. > > Cheers, > Bert > > > Bert Gunter > > "Data is not information. Information is not knowledge. And knowledge > is certainly not wisdom." > -- Clifford Stoll > > > On Fri, Jul 24, 2015 at 4:37 PM, Janh Anni <annijanh at gmail.com> wrote: > > Hello Jeff, > > > > Thanks a lot. I tried it and see that it prints out the entire 100 > partial > > sums, so I can take the last value as the partial sum for the first 100 > > terms. Would there be any way cumsum can print only the nth partial sum, > > i.e. the last value in the array, instead of printing the entire array? > > Thanks again. > > > > Joseph > > > > On Fri, Jul 24, 2015 at 2:02 PM, Jeff Newmiller < > jdnewmil at dcn.davis.ca.us> > > wrote: > > > >> Please reply-all so the mailing list stays in the loop. > >> > >> cumsum(1/(1:100)^2) > >> > >> gives you the partial sums up through i=100. > >> > --------------------------------------------------------------------------- > >> 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 July 24, 2015 10:30:09 AM PDT, Janh Anni <annijanh at gmail.com> wrote: > >> >Hello Jeff, > >> > > >> >Thank you so much for the suggestion, I searched cumsum as suggested > >> >but > >> >not sure it is what I had in mind. For instance if I had the infinite > >> >series: [image: Inline image 1] > >> > > >> >and want to compute the sum of the, say, first 100 terms, how could I > >> >use > >> >cusum to do that? > >> > > >> >Thanks again, > >> > > >> >Janh > >> > > >> > > >> >On Thu, Jul 23, 2015 at 11:51 PM, Jeff Newmiller > >> ><jdnewmil at dcn.davis.ca.us> > >> >wrote: > >> > > >> >> ?cumsum > >> >> > >> > >> > >--------------------------------------------------------------------------- > >> >> 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 July 23, 2015 8:23:39 PM PDT, Janh Anni <annijanh at gmail.com> > >> >wrote: > >> >> >Dear All, > >> >> > > >> >> >Does anyone know of any R functions that compute partial sums of > >> >> >series? > >> >> > > >> >> >Thanks in advance! > >> >> > > >> >> >Janh > >> >> > > >> >> > [[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. > >> >> > >> >> > >> > >> > > > > [[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. >[[alternative HTML version deleted]]
Wow! So many (simpler) ways to skin a cat. Thanks! On Fri, Jul 24, 2015 at 8:07 PM, David Winsemius <dwinsemius at comcast.net> wrote:> > On Jul 24, 2015, at 4:37 PM, Janh Anni wrote: > > > Hello Jeff, > > > > Thanks a lot. I tried it and see that it prints out the entire 100 > partial > > sums, so I can take the last value as the partial sum for the first 100 > > terms. Would there be any way cumsum can print only the nth partial sum, > > i.e. the last value in the array, instead of printing the entire array? > > Thanks again. > > Wouldn't that just mean using sum instead of cumsum????? > > Can even check the error from the analytical limit. > > > sum(1/(1:100)^2) - pi^2/6 > [1] -0.009950167 > > > > > > Joseph > > > > On Fri, Jul 24, 2015 at 2:02 PM, Jeff Newmiller < > jdnewmil at dcn.davis.ca.us> > > wrote: > > > >> Please reply-all so the mailing list stays in the loop. > >> > >> cumsum(1/(1:100)^2) > >> > >> gives you the partial sums up through i=100. > >> > --------------------------------------------------------------------------- > >> 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 July 24, 2015 10:30:09 AM PDT, Janh Anni <annijanh at gmail.com> wrote: > >>> Hello Jeff, > >>> > >>> Thank you so much for the suggestion, I searched cumsum as suggested > >>> but > >>> not sure it is what I had in mind. For instance if I had the infinite > >>> series: [image: Inline image 1] > >>> > >>> and want to compute the sum of the, say, first 100 terms, how could I > >>> use > >>> cusum to do that? > >>> > >>> Thanks again, > >>> > >>> Janh > >>> > >>> > >>> On Thu, Jul 23, 2015 at 11:51 PM, Jeff Newmiller > >>> <jdnewmil at dcn.davis.ca.us> > >>> wrote: > >>> > >>>> ?cumsum > >>>> > >> > >>> > --------------------------------------------------------------------------- > >>>> 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 July 23, 2015 8:23:39 PM PDT, Janh Anni <annijanh at gmail.com> > >>> wrote: > >>>>> Dear All, > >>>>> > >>>>> Does anyone know of any R functions that compute partial sums of > >>>>> series? > >>>>> > >>>>> Thanks in advance! > >>>>> > >>>>> Janh > >>>>> > >>>>> [[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. > >>>> > >>>> > >> > >> > > > > [[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. > > David Winsemius > Alameda, CA, USA > >[[alternative HTML version deleted]]