Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract part of time serie with R

Tags:

r

time-series

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?

like image 677
Paul Fournel Avatar asked Oct 21 '22 18:10

Paul Fournel


1 Answers

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
like image 101
Paul Fournel Avatar answered Oct 24 '22 00:10

Paul Fournel