Q:

The data has 238 entries and the residual should have 238 entries as well, why is it throwing an error of length difference?

I am attempting to plot a graph, but the error of length difference is preventing its execution. Why is there a length difference?
library("MASS")    

survey    
#data has 238

survfit <- lm(Height~Wr.Hnd, data =survey) 

residual <- resid(survfit)
#has 238 data points

plot(survey$Wr.Hnd, residual, ylab = "residuals", xlab = "Writing Handspan", main = "Residual plot")
#Error: x and y lengths differ

A:

The problem is NA that won't be computed in the resid function. Thus, you don't have the same length. Free to you on how you want to deal with that. But if you delete all rows with NA it works
survey2=na.omit(survey)

survfit <- lm(Height~Wr.Hnd, data =survey2) 
residual <- resid(survfit)

plot(survey2$Wr.Hnd, residual, ylab = "residuals", xlab = "Writing Handspan", main = "Residual plot")

