2
I have the following series:
library(zoo)
zoo_serie <- zoo(1:length(seq.Date(as.Date("1991-12-01"),as.Date("1998-12-31"),'day')),seq.Date(as.Date("1991-12-01"),as.Date("1998-12-31"),'day'))
I want to do a subset for the years 1991, 1995 and 1997, as I do it in an agile way?
Currently I create a series of dates and then I index in the series, this does not become feasible for huge series.
zoo_serie[index(zoo_serie) %in% vetor_de_datas]
I wanted something like this:
zoo_serie[year(index(zoo_serie)) %in% c(1911,1995,1997)]
But it doesn’t work. In the same way I wanted for specific months, this way I still haven’t managed.
The function
year
packagelubridate
does just that. The package has more functions to extract months, days and other date information.– Jorge Mendes
@Jorge-Mendes, put this as an answer.
– Carlos Eduardo Lagosta