Re: [R] Replace for loop when vector calling itself

2011-03-07 Thread rivercode
Hi, Thanks for your replies. In summary: 1. Replace code with c(0, cumsum(diff(theoP)) ). This is indeed correct and I had not realized it !! >> d = vector(mode = "numeric", length= len) >> d[1] = 0 >> if (len>1) for (i in 2:len) { d[i] = d[i-1] + theoP[i] - theoP[i-1] } 2. How to create

Re: [R] Replace for loop when vector calling itself

2011-03-07 Thread David Winsemius
om: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of David Winsemius Sent: Monday, March 07, 2011 10:52 AM To: rivercode Cc: r-help@r-project.org Subject: Re: [R] Replace for loop when vector calling itself On Mar 7, 2011, at 11:12 AM, rivercode wrote: Hope

Re: [R] Replace for loop when vector calling itself

2011-03-07 Thread David Reiner
e: [R] Replace for loop when vector calling itself On Mar 7, 2011, at 11:12 AM, rivercode wrote: > > Hope this clarifies my Q. > > Creating a vector where each element is (except the first which is > 0) is: > the previous element + a calculation from another vector theoP[i] - >

Re: [R] Replace for loop when vector calling itself

2011-03-07 Thread William Dunlap
nal Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of rivercode > Sent: Monday, March 07, 2011 8:12 AM > To: r-help@r-project.org > Subject: Re: [R] Replace for loop when vector calling itself > > > Hope this clarifies m

Re: [R] Replace for loop when vector calling itself

2011-03-07 Thread David Winsemius
On Mar 7, 2011, at 11:12 AM, rivercode wrote: Hope this clarifies my Q. Creating a vector where each element is (except the first which is 0) is: the previous element + a calculation from another vector theoP[i] - theoP[i-1] I could not figure out how to do this without a for loop, as t

Re: [R] Replace for loop when vector calling itself

2011-03-07 Thread rivercode
Hope this clarifies my Q. Creating a vector where each element is (except the first which is 0) is: the previous element + a calculation from another vector theoP[i] - theoP[i-1] I could not figure out how to do this without a for loop, as the vector had to reference itself for the next eleme

Re: [R] Replace for loop when vector calling itself

2011-03-07 Thread David Winsemius
On Mar 7, 2011, at 12:34 AM, rivercode wrote: Hi, I am missing something obvious. Need to create vector as: (0, i-1 + TheoP(i) - TheoP(i-1), repeat) Where i is the index position in the vector and i[1] is always 0. I think your prototype is not agreeing with the code below. Is "i"

[R] Replace for loop when vector calling itself

2011-03-07 Thread rivercode
Hi, I am missing something obvious. Need to create vector as: (0, i-1 + TheoP(i) - TheoP(i-1), repeat) Where i is the index position in the vector and i[1] is always 0. Found myself having to use a For Loop because I could not get sapply working. Any suggestions ? delta <- function(x)