The resid() function will calculate the residuals (error) from a model. That is, when given a model, it will take each case and calculate how far away the observed value is from the prediction of the model.
Example 1:
# Calculate the residuals from the empty model (the mean) of Thumb
# Use the lm() function to specify the model
resid(lm(Thumb ~ NULL, data = Fingers))
# Alt: Save the empty model into an object first
# then specify the name of the object as the argument
# (this method will produce the same output as the method above)
empty_model <- lm(Thumb ~ NULL, data = Fingers)
resid(empty_model)
Example output (truncated):
Example 2:
To see each residual in context, you might consider saving the predictions and the residuals into the data frame as new columns to see more closely what the resid() function is computing.
# Save the predictions and the residuals back into the data frame
Fingers$Thumb_predict <- predict(empty_model)
Fingers$Thumb_resid <- resid(empty_model)
# Select a few rows and the relevant columns to compare
head(select(Fingers, Thumb, Thumb_predict, Thumb_resid))
Example output: