[R] Catching an error with lm()

From: Ajay Narottam Shah <ajayshah_at_mayin.org>
Date: Tue 24 May 2005 - 20:35:05 EST


Folks,

I'm in a situation where I do a few thousand regressions, and some of them are bad data. How do I get back an error value (return code such as NULL) from lm(), instead of an error _message_?

Here's an example:

> x <- c(NA, 3, 4)
> y <- c(2, NA, NA)
> d <- lm(y ~ x)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :

        0 (non-NA) cases
> str(d)

Error in str(d) : Object "d" not found

My question is: How do I force lm() to quietly send back an error code like NULL? I am happy to then look at is.null(d) and handle it accordingly. I am stuck because when things go wrong, there is no object d to analyse!

(My production situation is a bit more complex. It is costly for me to first verify that the data is sound. I'd like to toss it into lm() and get an error code for null data).

-- 
Ajay Shah                                                   Consultant
ajayshah@mayin.org                      Department of Economic Affairs
http://www.mayin.org/ajayshah           Ministry of Finance, New Delhi

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue May 24 20:40:35 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:01 EST