I am new to R. I have an output of a function which when captured in a variable claims it is a list.
> typeof(fc)
[1] "list"
Here are the first few lines of how fc looks like
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
10229 -2.237542 -5.81116452 1.336080 -7.70292589 3.227841
10230 1.683324 -3.19974731 6.566396 -5.78468918 9.151337
10231 3.893685 -1.32257692 9.109948 -4.08389942 11.871270
.......
How to I make a vector with only say the Forecast column from this type. I googled around and figured that I should say fc$Forecast. But when I do that I get NULL printed. Much appreciate your time/help. Thanks.
As requested: The last few lines from dput output:
Names = c("method", "model", "level",
"mean", "lower", "upper", "x", "xname", "fitted", "residuals"
), class = "forecast")
And the first few lines.
structure(list(method = "ARIMA(4,0,2) with non-zero mean", model
= structure(list(coef = structure(c(0.261848480125606, 0.55212561713038,
0.00823985719608051, -0.051126398268002, -0.369141509818343,
1.60863444159457, -0.0928857946719395, -0.0901626797717415,
0.0526652165617547, -0.242259088064732, 0.164509902811429,
-0.149744064351169, 0.108818836027556, -0.0143040675162776
), .Names = c("ar1", "ar2", "ar3", "ar4", "ma1", "ma2", "intercept",
"S1", "C1", "S2", "C2", "S3", "C3", "S4", "C4")), sigma2 = 1.3269817639389,
var.coef = structure(c(0.494
Inbetween it is just a wall of 3 tuples.
You are getting the output of print.forecast which is not what the forecast-object actually looks like internally (as can be seen from the fragments of str(fc). AND … The name of the first column is not “Forecast” but rather `Point Forecast” (which will need quoting because of the embedded spaces). So after looking at print.forecast with getAnywhere I predicted you get your desired vector with the obvious modification of this (following execution of the example in help(forecast.Arima):
Therefore… try: