I have the following command to estimate the residuals from a linear regression and then merge it to the data. The data has missing values in the variable of interest but as I'm doing it on many variable I would like the residuals of my regression for NA values to just be NA.
I've seen on text that na.action=na.exclude should do the work just fine but it doesn't seems to do anything. Would you have an idea of why na.action is not working?
d <- lm(log(br_prix) ~ sectoryear, data=test,na.action = na.exclude)
P1 <- as.data.frame(d$residuals)
P1 <- P1 %>% dplyr::rename(lnprice = "d$residuals")
test <- cbind(test,P1)