I have a ts (time serie) object in R that contains long periods of missing value. I would like to extract a part of it and keep the time series object.
for example with the AirPassengers Data:
class(AirPassengers)
#output: "ts"
but if I extract only the 10 first month
AirPassengers[1:10]
#output: [1] 112 118 132 129 121 135 148 148 136 119
class(AirPassengers[1:10])
#output: "numeric"
How can I simply extract a part of my time serie without loosing the ts class?
As it was said here, the solution is to use the window
function:
window(AirPassergers, 1960, c(1960, 4))
Jan Feb Mar Apr
1960 417 391 419 461
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With