[R] How to say "if error"

Paul Chatfield p.s.chatfield at reading.ac.uk
Thu Jun 24 13:21:45 CEST 2010


Thanks Roman - you're right it can do more than I thought.  We're close now
to solving it I feel.  Essentially I'm trying to get the code below to work. 
If the condition is satisfied, it prints 2, but it doesn't save it in z.  I
want it to save it even though there's an error.  Perhaps you can easily see
what I'm missing,

x<-rnorm(0);y<-rnorm(0)
z<-ifelse(tryCatch(lm(y~x), finally=print(2))==1,
NA,lm(rnorm(10)~rnorm(10)))
-- 
View this message in context: http://r.789695.n4.nabble.com/How-to-say-if-error-tp2266619p2266782.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list