Why am I getting this error and how do I fix it?
Regression_Africa <- Mean_temperature_by_dt %>%
filter(Country == "Africa", dt >= 1850 & dt <=2013)
Regression_Africa <-lm(AverageTemperature ~ dt, data = Regression_Africa)
Temperature_predicted_temperature <- data.frame(Year = c(2015, 2016, 2020))
predict(Regression_Africa, Temperature_predicted_temperature) %>% round(1)
CodePudding user response:
We may need to match the names that was used in creation of the model. In addition, it is better to have a different object name for the model
other than the original dataset name (in case we want to use the input data again)
model <-lm(AverageTemperature ~ dt, data = Regression_Africa)
Temperature_predicted_temperature <- data.frame(dt = c(2015, 2016, 2020))
predict(model, newdata = Temperature_predicted_temperature)