Donny P Donny P - 1 year ago 89
R Question

Get the forecasted values when using forecast() in R

I did a forecast() in R, and I only want the forecasted values. How can I do this? If I use

I get extra information instead of a usable data object like a vector.


# 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)


Current Output:

Time Series:
Start = 6
End = 10
Frequency = 1
[1] 4.9999 4.9999 4.9999 4.9999 4.9999

Desired Output:

[1] 4.9999 4.9999 4.9999 4.9999 4.9999

Answer Source

Try stripping the ts attributes by coercing it into a simple numeric vector:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download