Re: [R] lm and NA

From: Kenn Konstabel <lebatsnok_at_gmail.com>
Date: Tue, 01 Jul 2008 15:53:14 +0300

use the function resid instead of lm.object$residuals to extract the residuals:

> resid(lm(a~b, na.action=na.exclude))

            1             2             3             4
5             6
-2.533445e-17  4.222409e-17 -8.444818e-18 -8.444818e-18
NA            NA

> lm(a~b, na.action=na.exclude)$residuals
1 2 3 4
-2.533445e-17 4.222409e-17 -8.444818e-18 -8.444818e-18

On Tue, Jul 1, 2008 at 12:07 AM, Georg Ehret <georgehret_at_gmail.com> wrote:

> Dear R community, Can I please get some advice on the following: I wish
> to obtain a list of residuals, padded by NAs for NAs in my source data. I
> tried several options of "na.action", but did not succeed...
>
> Example: I would like to get "0,0,0,0,NA,NA":
> > a
> [1] 1 2 3 4 NA 9
> > b
> [1] 3 4 5 6 7 NA
> > lm(a~b)$residuals
> 1 2 3 4
> 0 0 0 0
> > lm(a~b,na.action=na.exclude)$residuals
> 1 2 3 4
> 0 0 0 0
>
> Thank you and best regards!
> Georg.
> **************************
> Georg Ehret
> Johns Hopkins
> Baltimore, USA
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 01 Jul 2008 - 13:08:34 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Jul 2008 - 14:31:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive