I am trying to put the residuals from lm back into the original data.frame:
fit <- lm(y ~ x, data = mydata, weight = ind)
mydata$resid <- fit$resid
The second line would normally work if the residual has the same length as the number of rows of mydata. However, in my case, some of the elements of ind is NA. Therefore the residual length is usually less than the number of rows. Also fit$resid is a vector of "numeric" so there is no label for me to merge it back with the mydata data.frame. Is there an elegant way to achieve this?