Hey, I'm fairly new to R and came across an error I cannot seem to solve. My data has a fair amount of missing values, so when constructing a new column of the residuals using:
linear <- lm(LN_ratio_CD3_Blast ~ ID, data = CMI_LNratioCD3)
CMI_LNratioCD3$residual <- residuals(linear)
I get the following error: Error in $<-.data.frame(*tmp*, residual, value = c(317 = -1.27035435466668, : replacement has 244 rows, data has 1020
I've tried adding na.exclude, na.omit, na.pass, na.fill etc. but I seem to be doing something wrong...
In order to surpass this problem I've tried to not create the residual column, and just plot this in the qq plot directly:
Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.
There's also a nice FAQ on how to do a minimal reprex for beginners, below:
What to do if you run into clipboard problems
If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.
After running repress, I got a more detailed error and figured it out by myself. In short:
I've should have included the 'elimination' of the missingdata(NA) in the lm function when calculating the residuals with na.action=na.exclude
linear <- lm(LN_ratio_CD3_Blast ~ ID, data = CMI_LNratioCD3,na.action=na.exclude) > CMI_LNratioCD3$residual <- residuals(linear)