title: I am not able to get the metrics from Linear Regression in R for the test dataset
body: <p>I built the linear regression model. I have train and test the dataset. Train dataset has 9970 observations and the test dataset has 10000 observations. The total variable in the training dataset is 9 and the target variable is &quot;Earnings&quot;. My test dataset doesn't have Earnings, hence I need to predict it.</p>
  <p>My code as follows</p>
  <pre><code>
  lr_fit &lt;- lm(Earnings~., data = data)
  training_predictions &lt;- predict(lr_fit, newdata = data)
  R2(training_predictions, data$Earnings)
  </code></pre>
  <p>The above code is working and I can able to calculate the R2</p>
  <p>I am predicting the test dataset</p>
  <pre><code>testing_predictions &lt;- predict(lr_fit, newdata = test)
  R2(testing_predictions, test$Earnings)
  </code></pre>
  <p>I can able to predict, however, I am not getting the R-Square. Getting below message</p>
  <p><a href="https://i.stack.imgur.com/AXBvK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AXBvK.png" alt="enter image description here" /></a></p>
  <p>I am not able to solve this error. Please advise</p>