Skip to content
Prev 175220 / 398506 Next

how to get all iterations if I meet NaN?

2009/3/27 huiming song <huimings at gmail.com>:
not sure I properly understood. Consider:

 x = seq(-pi,pi,length=1001)
 z = sin(1/x)
# Warning message:
# In sin(1/x) : NaNs produced
x[500:502]; z[500:502]
# [1] -0.006283185  0.000000000  0.006283185
# [1] -0.8754095        NaN  0.8754095

one NaN and one warning have been created, the remaining 1000
calculations has been executed.

lim(x->0)sin(1/x) not exists so sin(1/0) is not a number nan

z1 = z[!is.nan(z)]
x1 = x[!is.nan(z)]

# x and z without the z's nan position

hope that help

Patrizio