Hi Everyone, I am stuck with a simple problem. Suppose I have a vector x, and I want to calculate y[i]=3Dx[i+1]-x[i], it is very easy. I just need to write y<-x[2:length(x)]-x[1:length(x)-1]. Now if I know y, and want to know the vector x defined by x[i]=3Dx[i-1]+y[i-1] for all i, how can I do this without a loop? Thanks, Geoffrey PS. Sorry if you see a duplicate message. The previous one was in a weird format that most people would not be able to read. _______________________________________________________=0A=0A=0AThe information in this email or in any file attached hereto is=0Aintended only for the personal and confidential use of the individual=0Aor entity to which it is addressed and may contain information that is=0Aproprietary and confidential. If you are not the intended recipient of=0Athis message you are hereby notified that any review, dissemination,=0Adistribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email transmission cannot be guaranteed to be secure or error-free.
> x[i]=3Dx[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?
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] )? Thanks, Geoffrey -----Original Message----- From: Richard M. Heiberger [mailto:rmh at temple.edu] Sent: Tuesday, December 26, 2006 9:56 AM To: Geoffrey Zhu; r-help at stat.math.ethz.ch 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? _______________________________________________________=0A=0A=0AThe information in this email or in any file attached hereto is=0Aintended only for the personal and confidential use of the individual=0Aor entity to which it is addressed and may contain information that is=0Aproprietary and confidential. If you are not the intended recipient of=0Athis message you are hereby notified that any review, dissemination,=0Adistribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email transmission cannot be guaranteed to be secure or error-free.
I meant x[i] <- x[i-1] + y[i-1] and Y[i] <- y[i-1] + x[i] below. The mailing list software just keep adding 3D's. Sorry. -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Geoffrey Zhu Sent: Tuesday, December 26, 2006 10:03 AM To: Richard M. Heiberger; r-help at stat.math.ethz.ch Subject: Re: [R] vectorizing an iterative process. Hi Richard, 3D is automatically generated by the mailing list software, probably because I had ] followed by =3D3D without a space in the original post. What I meant was to calculate x[i] =3D3D 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] =3D3D 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] )? Thanks, Geoffrey -----Original Message----- From: Richard M. Heiberger [mailto:rmh at temple.edu] Sent: Tuesday, December 26, 2006 9:56 AM To: Geoffrey Zhu; r-help at stat.math.ethz.ch Subject: Re: [R] vectorizing an iterative process.> x[i]=3D3D3Dx[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? _______________________________________________________=3D0A=3D =3D0A=3D =3D0A=3D The information in this email or in any file attached hereto is=3D0A=3D intended only for the personal and confidential use of the individual=3D0A=3D or entity to which it is addressed and may contain information that is=3D0A=3D proprietary and confidential. If you are not the intended recipient of=3D0A=3D this message you are hereby notified that any review, dissemination,=3D0A=3D distribution or copying of this message is strictly prohibited. This communi=3D cation is for information purposes only and should not be regarded as an off=3D er to sell or as a solicitation of an offer to buy any financial product. Em=3D ail transmission cannot be guaranteed to be secure or error-free. ______________________________________________ R-help at stat.math.ethz.ch mailing list 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. _______________________________________________________=0A=0A=0AThe information in this email or in any file attached hereto is=0Aintended only for the personal and confidential use of the individual=0Aor entity to which it is addressed and may contain information that is=0Aproprietary and confidential. If you are not the intended recipient of=0Athis message you are hereby notified that any review, dissemination,=0Adistribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email transmission cannot be guaranteed to be secure or error-free.
Yes, this solves my problem. Thanks for your help. -----Original Message----- From: Christos Hatzis [mailto:christos at nuverabio.com] Sent: Tuesday, December 26, 2006 10:58 AM To: Geoffrey Zhu; r-help at stat.math.ethz.ch Subject: RE: [R] vectorizing an iterative process. In your case, the recurrence relationship for x can be solved easily: Notice that sum{i=3D1,n}(x[i]-x[i-1]) =3D x[n] - x[0] and therefore x[n] =3D x[0] + sum{i=3D1,n}(y[i-1] for n=3D1, N, with the appropriate initial condition for i=3D0, (x[0],y[0]). Thus cumsum on y will give you a direct answer. -Christos Christos Hatzis, Ph.D. Nuvera Biosciences, Inc. 400 West Cummings Park Suite 5350 Woburn, MA 01801 Tel: 781-938-3830 www.nuverabio.com -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Geoffrey Zhu Sent: Tuesday, December 26, 2006 11:06 AM To: r-help at stat.math.ethz.ch Subject: Re: [R] vectorizing an iterative process. I meant x[i] <- x[i-1] + y[i-1] and Y[i] <- y[i-1] + x[i] below. The mailing list software just keep adding 3D's. Sorry. -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Geoffrey Zhu Sent: Tuesday, December 26, 2006 10:03 AM To: Richard M. Heiberger; r-help at stat.math.ethz.ch Subject: Re: [R] vectorizing an iterative process. Hi Richard, 3D is automatically generated by the mailing list software, probably because I had ] followed by =3D3D3D without a space in the original post. What I meant was to calculate x[i] =3D3D3D 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] =3D3D3D 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] )? Thanks, Geoffrey -----Original Message----- From: Richard M. Heiberger [mailto:rmh at temple.edu] Sent: Tuesday, December 26, 2006 9:56 AM To: Geoffrey Zhu; r-help at stat.math.ethz.ch Subject: Re: [R] vectorizing an iterative process.> x[i]=3D3D3D3Dx[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? _______________________________________________________=3D3D0A=3D3D =3D3D0A=3D3D =3D3D0A=3D3D The information in this email or in any file attached hereto is=3D3D0A=3D3D intended only for the personal and confidential use of the individual=3D3D0A=3D3D or entity to which it is addressed and may contain information that is=3D3D0A=3D3D proprietary and confidential. If you are not the intended recipient of=3D3D0A=3D3D this message you are hereby notified that any review, dissemination,=3D3D0A=3D3D distribution or copying of this message is strictly prohibited. This communi=3D3D cation is for information purposes only and should not be regarded as an off=3D3D er to sell or as a solicitation of an offer to buy any financial product. Em=3D3D ail transmission cannot be guaranteed to be secure or error-free. ______________________________________________ R-help at stat.math.ethz.ch mailing list 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. _______________________________________________________=3D0A=3D =3D0A=3D =3D0A=3D The information in this email or in any file attached hereto is=3D0A=3D intended only for the personal and confidential use of the individual=3D0A=3D or entity to which it is addressed and may contain information that is=3D0A=3D proprietary and confidential. If you are not the intended recipient of=3D0A=3D this message you are hereby notified that any review, dissemination,=3D0A=3D distribution or copying of this message is strictly prohibited. This communi=3D cation is for information purposes only and should not be regarded as an off=3D er to sell or as a solicitation of an offer to buy any financial product. Em=3D ail transmission cannot be guaranteed to be secure or error-free. ______________________________________________ R-help at stat.math.ethz.ch mailing list 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. _______________________________________________________=0A=0A=0AThe information in this email or in any file attached hereto is=0Aintended only for the personal and confidential use of the individual=0Aor entity to which it is addressed and may contain information that is=0Aproprietary and confidential. If you are not the intended recipient of=0Athis message you are hereby notified that any review, dissemination,=0Adistribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product. Email transmission cannot be guaranteed to be secure or error-free.