I am looking for a method to bind lm
residuals to an input dataset. The method must add NA
for missing residuals and the residuals should correspond to the proper row.
Sample data:
N <- 100
Nrep <- 5
X <- runif(N, 0, 10)
Y <- 6 + 2*X + rnorm(N, 0, 1)
X[ sample(which(Y < 15), Nrep) ] <- NA
df <- data.frame(X,Y)
residuals(lm(Y ~ X,data=df,na.action=na.omit))
Residuals should be bound to df.