[R] Impute missing data by regression in R

Peter Langfelder peter.langfelder at gmail.com
Fri Oct 15 07:40:56 CEST 2010


I assume you mean regression of x on y...

here's the code:

missing = is.na(x)
predicted = predict(lm(x~y))
x[missing] = predicted[missing];

Should work but please check.

Peter

On Thu, Oct 14, 2010 at 10:14 PM, Jumlong Vongprasert
<jumlong.ubru at gmail.com> wrote:
>  Dear all
> I have data (x,y) with data x is missing in 5 record of 100 record.
> I want to impute data x by use regression.
> How I can do this.
> THX
> Jumlong



More information about the R-help mailing list