【发布时间】:2021-03-14 23:49:19
【问题描述】:
我有一个数据集,其中包含一段时间内每月 1 日开始的月度数据。
这是我的日期列的 head():
> class(gas_data$Date)
[1] "Date"
> head(gas_data$Date)
[1] "2010-10-01" "2010-11-01" "2010-12-01" "2011-01-01" "2011-02-01" "2011-03-01"
试图使时间序列静止,我正在使用基本包中的 diff():
> gas_data_diff <- diff(gas_data, differences = 1, lag = 12)
> head(gas_data_diff)
data frame with 0 columns and 6 rows
> names(gas_data_diff)
character(0)
> gas_data_diff %>%
+ ggplot(aes(x=Date, y=Price.Gas)) +
+ geom_line(color="darkorchid4")
Error in FUN(X[[i]], ...) : object 'Price.Gas' not found
如您所见,我收到了一个错误,当尝试使用 head() 可视化数据或查找特征名称时,我收到了意外的输出。
为什么会出现此错误,我该如何解决?
这是我原始数据的 head()
> head(gas_data)
Date Per.Change Domestic.Production.from.UKCS Import Per.GDP.Growth Average.Temperature Price.Electricity Price.Gas
1 2010-10-01 2.08 3.54 5.40 0.2 10.44 43.50 46.00
2 2010-11-01 -3.04 3.46 6.74 -0.1 5.52 46.40 49.66
3 2010-12-01 0.31 3.54 9.00 -0.9 0.63 58.03 62.26
4 2011-01-01 2.65 3.59 7.58 0.6 4.05 48.43 55.98
5 2011-02-01 1.52 3.20 5.68 0.4 6.29 46.47 53.74
6 2011-03-01 -1.38 3.40 5.93 0.5 6.59 51.41 60.39
【问题讨论】:
标签: r time-series forecasting arima