When I forecast from a linear Regression model in R using the following code, I get an arguments of length zero error , which I understand as a null pointer:
library(forecast)
Mwh = c(16.3,16.8,15.5,18.2,15.2,17.5,19.8,19.0,17.5,16.0,19.6,18.0)
temp = c(29.3,21.7,23.7,10.4,29.7,11.9,9.0,23.4,17.8,30.0,8.6,11.8)
t=data.frame(Mwh,temp)
fit = lm(Mwh~temp,data=t)
fcast=forecast(fit,newdata=35)
However, the following code, which looks very, very similar to me, does not produce the error, but the forecast as desired - why? Where is my blind spot? This works:
library(forecast)
electricity =c(16.3,16.8,15.5,18.2,15.2,17.5,19.8,19.0,17.5,16.0,19.6,18.0)
maximumDailyTemp= c(29.3,21.7,23.7,10.4,29.7,11.9,9.0,23.4,17.8,30.0,8.6,11.8)
d = data.frame(maximumDailyTemp, electricity)
fit<-lm(electricity ~ maximumDailyTemp , data=d)
electricityForecast<-forecast(fit,newdata=35)
Why is there an error above and no error below? The order of variables in the data Frames cannot be the reason, right?