简体   繁体   中英

Subsetting winter (Dez, Jan, Feb) from daily time series (zoo)

I have a daily zoo (xts) with a few decades of data in the following format:

head(almorol)
1973-10-02 1973-10-03 1973-10-04 1973-10-05 1973-10-06 1973-10-07
     183.9      208.2      153.7       84.8       52.5       35.5

and I would like to plot just winter data (the full months of December, January and February). I found the subsetting for xts so I thought I could extract all the Decembers using:

x<-apply.yearly(almorol, FUN=last(almorol, "1 month"))

and then do something similar for Jan and Feb, but I get the following error:

Error in get(as.character(FUN), mode = "function", envir = envir) :
object 'FUN' of mode 'function' was not found

I can use the apply.yearly and last(almorol, "1 month") separately but when I combine them it doesn't work. Does anyone know a way of subsetting those 3 months of the time series? Thanks for helping!

Try this:

z.winter <- z[months(time(z), TRUE) %in% c("Dec", "Jan", "Feb")]
plot(z.winter)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM