working with a data frame
x
Date Val
1/1/2012 7
2/1/2012 9
3/1/2012 20
4/1/2012 24
5/1/2012 50
a <- seq(as.Date(tai
Your variable names, as stored in the x.lm
model, refer to the x
dataframe. There are no variables of the same names in a
, so it will use those 29 from x
again, which is probably not what you wanted, thus the warning. You can do the following to always use an unqualified variable named Date
in the model:
a <- seq(as.Date(tail(x, 1)$Date), by="month", length=5)
a <- data.frame(Date = a)
x.lm <- lm(Val ~ Date, data=x)
x.pre<-predict(x.lm, newdata=a)