R is given me a warning which say "longer object length is not a multiple of shorter object length"
I kind of know the issue. I think the train_set is a list and yhat_test is a double, which is why i am getting the warning.
I think it is more likely to be a result of the difference in lengths of train_set$dis and yhat_test.
While you're finding test error, shouldn't you compare the predictions for test dataset with the expected results of test dataset? Why are you comparing with expectations of the training dataset? My point is, don't you want this?
mean((test_set$dis - yhat_test)^2)
If this is not the case, can you please provide a REPRoducible EXample of your problem? It provides more specifics of your problem, and it helps others to understand what problem you are facing.
If you don't know how to do it, take a look at this thread: