我在R中做了一个forecast(),我只想要预测值。我怎样才能做到这一点?如果我使用forecast$means
,我会得到额外的信息,而不是像矢量那样的可用数据对象。
suppressMessages(require('forecast'))
suppressMessages(require('rjson'))
# Load data. Let user choose what file they want to input.
my_json = "[1,2,3,4,5]"
my_data = fromJSON(my_json)
my_df = data.frame(my_data)
# Plot the decomposed time series. Let user choose their season length.
forecasted_data = forecast(ts(my_df[,1]), h=5)
print(forecasted_data$mean)
当前输出:
Time Series:
Start = 6
End = 10
Frequency = 1
[1] 4.9999 4.9999 4.9999 4.9999 4.9999
期望的输出:
[1] 4.9999 4.9999 4.9999 4.9999 4.9999
答案 0 :(得分:6)
尝试通过将ts
属性强制转换为简单的numeric
向量来剥离as.numeric(forecasted_data$mean)
属性:
{{1}}
答案 1 :(得分:-1)
Forecasted_data‹-data.frame(forecasted_data)
View(forecasted_data)