0

I am trying to predict using simple linear model. But everytime I get warning:

Warning message: 'newdata' had 2 rows but variables found have 62 rows

Here is my code:-

fit<-lm(mean ~ year,data=data)

fit

summary(fit)

years<-data.frame(year=c(2020,2019))

predict.lm(m,newdata = years)

It is a simple data set containing year (till 2020) and carbon emission as columns. and I am trying to predict carbon emission for year 2030.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 1
    Your model name is fit, so why calling `m` inside. Shouldn't be `predict(fit, newdata=years)` – PKumar Apr 07 '21 at 19:17
  • 1
    do any of the "related" questions (listed on the side bar) that refer to this warning message have any useful information? – Ben Bolker Apr 07 '21 at 19:20
  • 1
    It's easier to help you if you include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. The code you posted isn't runnable and it sounds like you may have left out the actual cause of the error. – MrFlick Apr 07 '21 at 19:23

0 Answers0