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 comparison from the next value). It works well as long as I have numeric values in my data. But if my data ends with NAs, I have this problem. That's why I'm trying to ask him to stop the calculation in the loop at the last numeric value to avoid this error (don't know if it's the best way to solve it, but it's the main idea I think). Have you got any other idea about this? Thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/stop-calculation-in-a-function-tp4622964p4623259.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ [email protected] 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.

