使用数据框架
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(tail(x, 1)$Date), by="month", length=5)
a <- data.frame(a)
x.lm <- lm(x$Val ~ x$Date)
x.pre<-predict(x.lm, newdata=a)
I am getting this erro:
Warning message:
'newdata' had 5 rows but variable(s) found have 29 rows
我做错了什么?
这是dput输出:
dput(x)
structure(list(Date = structure(c(14610, 14641, 14669, 14700,
14730, 14761, 14791, 14822, 14853, 14883, 14914, 14944, 14975,
15006, 15034, 15065, 15095, 15126, 15156, 15187, 15218, 15248,
15279, 15309, 15340, 15371, 15400, 15431, 15461), class = "Date"),
Val = c(45, 51, 56, 56, 59, 60, 60, 60, 64, 65, 75, 73, 74,
80, 87, 91, 92, 96, 109, 108, 123, 129, 133, 143, 127, 127,
123, 121, 130)), .Names = c("Date", "Val"), row.names = c(NA,
29L), class = "data.frame")
z
应该是一个x
吗?否则我们不知道z
是什么。你没有收到错误,而是收到了一个警告。另外,你展示给我们的数据没有29行,所以我们无法重复你的问题。请使用dput
函数向我们展示你的实际数据。 - Justin