Re: [R] Sequences

2009-04-08 Thread Eik Vettorazzi
Hi Melissa, so what you want to calculate is something like S-cumsum(lambs)-(1:length(lambs))*mean(lambs) since (with x.bar=mean(x)) S_1=x_1-x.bar S_2=S1+(x_2-x.bar)=x_1-x.bar+x_2-x_bar=x_1+x_2-2*x.bar ... S_n=S_(n-1)+x_n-x.bar=sum_i (x_i)-n*x.bar Eik. m.mcquil...@lancaster.ac.uk schrieb:

[R] Sequences

2009-04-07 Thread Melissa2k9
Hi, I am trying to make a sequence and am using a for loop for this. I want to start off with an initial value ie S[0]=0 then use the loop to create other values. This is what I have so far but I just keep getting error messages. #To calculate the culmulative sums: s-rep(0,207)

Re: [R] Sequences

2009-04-07 Thread David Winsemius
Think about what i-1 would be the first time though the loop. R doesn't like 0 as an index. You are going to need to decide what you consider to the the previous value for the first element in your vector. If you want cumulative sums, then look at the function cumsum ?cumsum On Apr 7,

Re: [R] Sequences

2009-04-07 Thread Eik Vettorazzi
Hi Melissa, first of all in R indexes of vectors starts with 1 not with 0. So s[0]-0 doesn't make sense here (minor second point R is also case sensitive, so S[] is not the same as s[]). Secondly rep() returns already a vector, so as.vector(s) is not necessary. Thirdly, loops are bad under

Re: [R] Sequences

2009-04-07 Thread Stavros Macrakis
On Tue, Apr 7, 2009 at 8:13 AM, Melissa2k9 m.mcquil...@lancaster.ac.ukwrote: I am trying to make a sequence and am using a for loop for this. I want to start off with an initial value ie S[0]=0 then use the loop to create other values. This is what I have so far but I just keep getting error

Re: [R] Sequences

2009-04-07 Thread Gene Leynes
Not sure what you're trying to accomplish, but I think the index values are off. the first element of s is 1, not 0 Here's something that works: s-rep(0,207) s-as.vector(s) s[0]-0 lambs=rep(rnorm(207)*1000) for (i in 1:(length(lambs)-1)){ s[i]-s[i+1]-mean(lambs) } On Tue, Apr 7, 2009

Re: [R] Sequences

2009-04-07 Thread Bert Gunter
-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Stavros Macrakis Sent: Tuesday, April 07, 2009 9:11 AM To: Melissa2k9 Cc: r-help@r-project.org Subject: Re: [R] Sequences On Tue, Apr 7, 2009 at 8:13 AM, Melissa2k9 m.mcquil...@lancaster.ac.ukwrote: I am trying to make a sequence and am

Re: [R] Sequences

2009-04-07 Thread Stavros Macrakis
[mailto:r-help-boun...@r-project.org] On Behalf Of Stavros Macrakis Sent: Tuesday, April 07, 2009 9:11 AM To: Melissa2k9 Cc: r-help@r-project.org Subject: Re: [R] Sequences On Tue, Apr 7, 2009 at 8:13 AM, Melissa2k9 m.mcquil...@lancaster.ac.ukwrote: I am trying to make a sequence and am

Re: [R] Sequences

2009-04-07 Thread Bernardo Rangel Tura
On Tue, 2009-04-07 at 05:16 -0700, Melissa2k9 wrote: Hi, I am trying to make a sequence and am using a for loop for this. I want to start off with an initial value ie S[0]=0 then use the loop to create other values. This is what I have so far but I just keep getting error messages. #To