[R] how to get all iterations if I meet NaN?

Nash morrison at ibms.sinica.edu.tw
Sun Mar 29 10:10:15 CEST 2009


Okay!

Thank you!

On Sun, 29 Mar 2009 10:01:29 +0200, Peter Dalgaard wrote
> Nash wrote:
> >> Uwe Ligges wrote:
> >> Please read the question more carefully, the sin() example was used 
> >> as a method that does not give an error but works as expected (just 
> >> with the warning), but the question is how not to break the loop,
> >>  and so my answer was "see ?try".
> > 
> > So,
> > Do you have any solution about his problem ?
> >
> 
> 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)
> }
> 
> -- 
>     O__  ---- Peter Dalgaard             喒ter Farimagsgade 5, Entr.B
>    c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
> 
>   (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907


--
Nash - morrison at ibms.sinica.edu.tw




More information about the R-help mailing list