RE: [R] lm(y~x) question: removing NAs

About this list Date view Thread view Subject view Author view Attachment view

From: Liaw, Andy (andy_liaw@merck.com)
Date: Tue 04 May 2004 - 23:45:47 EST


Message-id: <3A822319EB35174CA3714066D590DCD504AF7CF6@usrymx25.merck.com>

By (`factory') default that's done for you automagically, because
options("na.action") is `na.omit'.

If you really want to do it `by hand', and have the data in a data frame,
you can use something like:

lm(y ~ x, df[complete.cases(df),])

HTH,
Andy

> From: Christoph Scherber
>
> Dear all,
>
> I have a data frame with different numbers of NAs in each
> column, e.g.:
>
> x y
> 1 2
> NA 3
> NA 4
> 4 NA
> 1 5
> NA NA
>
>
> I now want to do a linear regression on y~x with all the NAs
> removed.
> The problem now is that is.na(x) (and is.na(y) obviously
> gives vectors
> with different lengths. How could I solve this problem?
>
> Thank you very much for any help.
>
> Best regards
> Chris
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:07 EST