I would like to turn a monthly time series into a quarterly one, by only keeping 4 values from the year. I have a date column in a dataframe as an integer in this monthly format:
192707
192708
192709
....
I have converted it to date format:
library(zoo)
df$date<-as.Date(as.yearmon(as.character(df$date), format = '%Y%m'), frac=1)
Next I was thinking to keep only 4 months of the year (Jan, Apr, Jul, Oct) with something like this, but I am not sure how to exactly do this:
df<-subset(df, month(df$date)==1 | month(df$date)==4 |
month(df$date)==7 | month(df$date)==10)
Is there a way to extract the month from the date column?
ymwithout converting it to Date usingcycle(ym). - G. Grothendieck