Re: [R] stop calculation in a function

2012-05-10 Thread jeff6868
I tried your proposition Sarah (I was answering to Berend when you posted your answer). Well it seems to work! I just had to add afterwords a line to have my NAs again. I converted values = 0 by NA (numeric() in the function did the contrary for the calculation): mydata[mydata==0] <- NA At firs

Re: [R] stop calculation in a function

2012-05-10 Thread Sarah Goslee
You're moving the goal posts. If you need to deal with internal as well as terminal NA values in a particular way, it would help to have told us that up front. Please give us some sample data that illustrates what you're really trying to work with, and a full explanation of what you need to accomp

Re: [R] stop calculation in a function

2012-05-10 Thread jeff6868
Thanks for your answer too Berend. Yes you're right about x[i+1]. You answered juste before me. Well your idea of declaring all in numeric is great. It avoids my problem. But actually I also have small missing data gaps in the rest of my data (in the middle of numeric values). And one of the aim of

Re: [R] stop calculation in a function

2012-05-10 Thread Sarah Goslee
On Thu, May 10, 2012 at 8:02 AM, jeff6868 wrote: > Thank you for your reply sarah. > Well actually I don't try to access x[i+1]. The line where you saw it starts > with #. It was just try I wanted to keep (sorry I should have removed it > before posting). Sorry, I should really have more coffee b

Re: [R] stop calculation in a function

2012-05-10 Thread jeff6868
Thank you for your reply sarah. Well actually I don't try to access x[i+1]. The line where you saw it starts with #. It was just try I wanted to keep (sorry I should have removed it before posting). But I ask him to access to the next value if conditions in the loop are not verified (restart the c

Re: [R] stop calculation in a function

2012-05-10 Thread Berend Hasselman
On 10-05-2012, at 12:59, Sarah Goslee wrote: > Well, if i goes from 2 to length(x) and you try to access x[i+1], of > course odd things will happen. Why not construct the loop to > (length(x)-1) instead, so that x[i+1] is defined. > The reference to x[i+1] in a commented line so I don't think

Re: [R] stop calculation in a function

2012-05-10 Thread Sarah Goslee
Well, if i goes from 2 to length(x) and you try to access x[i+1], of course odd things will happen. Why not construct the loop to (length(x)-1) instead, so that x[i+1] is defined. Sarah On Thu, May 10, 2012 at 5:14 AM, jeff6868 wrote: > Hi dear R-users, > > I have a question about a function I