Skip to content
Back to formatted view

Raw Message

Message-ID: <49CD245D.9020209@statistik.tu-dortmund.de>
Date: 2009-03-27T19:09:17Z
From: Uwe Ligges
Subject: how to get all iterations if I meet NaN?
In-Reply-To: <54d792b30903271036s51159ad8y5d12fbfef4b0ad53@mail.gmail.com>

huiming song wrote:
> hi, everybody, please help me with this question:
> 
> If I want to do iteration for 1000 times, however, for the 500th iteration,
> there is NaN appears. Then the iteration will stop. If I don't want the stop
> and want the all the 1000 iterations be done. What shall I do?
> 
> 
> suppose I have x[1:1000] and z[1:1000],I want to do some calculation for all
> x[1] to x[1000].
> 
> z=rep(0,1000)
> for (i in 1:1000){
>   z[i]=sin(1/x[i])
> }
> 
> if x[900] is 0, in the above code it will not stop when NaN appears. Suppose
> when sin(1/x[900]) is NaN appears and the iteration will now fulfill the
> rest 100 iterations. How can I write a code to let all the 1000 iterations
> be done?


See ?try

Uwe Ligges


> Thanks!
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org 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.