【发布时间】:2020-03-21 16:37:52
【问题描述】:
我有一个关于如何将 df 转换为时间序列的问题。我是 R 新手,我正在为这个操作而苦苦挣扎。
这些是我的 df 的一些行,名为“test”:
> test
SM weekY week art cat flagP Woy year ispromo yval yqta price ln_yval ln_price
<chr> <chr> <date> <chr> <chr> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 11111 2016/01 2016-01-03 Z0005 C10 0 01 2016 0 59839. 4060 14.7 11.0 2.69
2 11111 2016/02 2016-01-10 Z0005 C10 0 02 2016 0 38186. 2640 14.5 10.6 2.67
3 11111 2016/03 2016-01-17 Z0005 C10 0 03 2016 0 38986. 2660 14.7 10.6 2.68
我的日期变量是“星期”,它的频率不一定等于 7,因为缺少某些日期。我想将此 df 转换为时间序列,其中“周”是要考虑的日期。我的目标是将此 df 用于预测目的。特别是,我想使用应用于时间序列的多元线性回归
####example where XXXXXXX is the converted df to time series and I am using some variables for lin. regr.
fit_test <- tslm(ln_yval ~ SM + cat + ispromo, data=XXXXXXX)
autoplot(XXXXXXX[,'ln_yval '], series="Data") +
autolayer(fitted(fit_test), series="Fitted")
感谢您的帮助
【问题讨论】:
标签: r dataframe time-series forecast