当一个数据帧警告计算预测值
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)
我得到这个工作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 2012-08-03 20:47:27
对不起,是的,它是x。我只是更新它 – user1471980 2012-08-03 20:50:32