Friday, 15 April 2011

missing data - R knnImpute not working -



missing data - R knnImpute not working -

i have next code example:

df = data.frame(x=c(100:104,nan,106:110),y=c(200:204,nan,206:210)) s = preprocess(df,method="knnimpute")

when utilize predict function using next code:

pre = predict(s,df)

r crashes , have restart.

what wrong code above? also, need 2 columns knnimpute work?

gregory jefferis, maintains bundle cleared mystery: preprocessing knnimpute silently removes columns containing na values, both variables x , y lost before predict(). here illustration works without crashing. trick have few more related columns without nas.

x=rnorm(100); y=rnorm(100) z1 = x+2*y + rnorm(100,sd=0.1) z2 = 3*x+2 + rnorm(100,sd=0.3) z2 = 2*y+8 + rnorm(100,sd=0.3) df = data.frame(x,y,z1,z2) head(df) df[25, 1] = na df[50, 2] = na xform = preprocess(df, method="knnimpute") predict(xform, df)

r missing-data

No comments:

Post a Comment