Skip to content
Prev 175312 / 398506 Next

how to get all iterations if I meet NaN?

Nash wrote:
Yes he does: Use try().

This may not be very specific, but neither was the original question. 
The poster didn't give an example that we could fix, only the sin() 
example that he wanted his own code to work _like_.

So to answer the question with working code, one first needs to invent a 
broken example. Perhaps something like

for(i in 2:-2) {
    x <- try(chol(as.matrix(i)))
    if(inherits(x,"try-error")) x <- NaN
    print(x)
}