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

て烟熏妆下的殇ゞ 提交于 2019-11-30 15:59:02

问题


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!


回答1:


Try this:

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


来源:https://stackoverflow.com/questions/6356829/subsetting-winter-dez-jan-feb-from-daily-time-series-zoo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!