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
*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:
residual <- residuals(linear)
g5 <-ggplot(data = CMI_LNratioCD3,
aes(sample = residual))+
geom_qq_line(colour = "red") +
labs(title = "Quantile plot of residuals")
However, this will result in the following error: Error: Aesthetics must be either length 1 or the same as the data (1020): sample
Can someone please tell me what might be going on? And how I can solve this?