1

I have an object forecast. When I execute:

class(forecast)

I get:

[1] "mts"    "ts"     "matrix"

Does this mean that this is a list of 3 objects of which the last one is a matrix?

When I do:

str(forecast)

I get:

 Time-Series [1:5, 1:3] from 8153 to 8157: 52 52 52 51 51 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:3] "fit" "upr" "lwr"

When I do:

head(forecast)

I get:

          fit      upr      lwr
[1,] 51.77675 57.21211 46.34138
[2,] 51.67965 57.22266 46.13664
[3,] 51.58255 57.36042 45.80468
[4,] 51.48545 57.65884 45.31206
[5,] 51.38835 58.13347 44.6432

How do I get the separate values of the first row as indicated by this pseudo code please:

          fit      upr      lwr
[1,] 51.77675 57.21211 46.34138

fit <- ?
upr <- ?
lwr <- ?
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
cs0815
  • 16,751
  • 45
  • 136
  • 299

1 Answers1

1

If an object has multiple classes, it can be processed as any one class (although the generic function normally picks up the first class for method dispatching, see How to extract coefficients' standard error from an "aov" model for an example).

A "mts" class is for a multivariate time series, it is a mixture of "matrix" class and "ts" class. You can access it as an ordinary matrix.

forecast[1, , drop = FALSE]  ## row 1

fit <- forecast[1, 1]
upr <- forecast[1, 2]
lwr <- forecast[1, 3]
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248