Re: [R] vectorizing an iterative process.

From: Geoffrey Zhu <>
Date: Tue 26 Dec 2006 - 16:02:35 GMT

Hi Richard,

3D is automatically generated by the mailing list software, probably because I had ] followed by =3D without a space in the original post.

What I meant was to calculate x[i] =3D x[i-1] + y[i-1]

For example, if X <- 1:10

Then I want the vector Y to be 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, or in other words Y[i] =3D y[i-1] + x[i].

Yes, cumsum does the trick for this. This is what I need. Thanks.

Just curious, do you know how to calculate the more generic x[i] <- f( x[i-1], y[i-1] )?


-----Original Message-----
From: Richard M. Heiberger [] Sent: Tuesday, December 26, 2006 9:56 AM To: Geoffrey Zhu; Subject: Re: [R] vectorizing an iterative process.

> x[i]=3D3Dx[i-1]+y[i-1] for all i, how can I do this without a loop?

It looks like

   x <- cumsum(y)

What does 3D mean?

The information in this email or in any file attached hereto is=0A= intended only for the personal and confidential use of the individual=0A= or entity to which it is addressed and may contain information that is=0A= proprietary and confidential. If you are not the intended recipient of=0A= this message you are hereby notified that any review, dissemination,=0A=
distribution or copying of this message is strictly prohibited. This communi=
cation is for information purposes only and should not be regarded as an off=
er to sell or as a solicitation of an offer to buy any financial product. Em=
ail transmission cannot be guaranteed to be secure or error-free. mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed Dec 27 03:22:38 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 26 Dec 2006 - 17:30:27 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.