subset xts zoo 获取仅需一个月

subset xts zoo to obtain only one month

我有一个每月的 xts/zoo 时间序列对象,我想对其进行子集化,以便我只获得 11 月份的值。所以对于每一年,我只想要 11 月份。这是对象(已下载):

library(quantmod)
indPro<-getSymbols('INDPRO', src="FRED", auto.assign=FALSE)

有人知道怎么做吗?

数据是这样的:

           INDPRO
1919-01-01 5.0346
1919-02-01 4.8121
1919-03-01 4.6730

您的数据是什么样的?

假设您的数据看起来有点像: df$Date = c(10-01-2015 12:22:00, 等等)

我过去用过 dplyrzoo - 试试 df <- df %>% filter(month(Date) == 11)

试试这个:

indPro[.indexmon(indPro) == 10,]

0 是 1 月,1 月是 2 月,... 11 是 12 月。

您还发现了解以下内容很有用:

.indexyear
.indexday
.indexweek
.indexhour
.indexmin
.indexsec

查看 ?.indexsec 的帮助了解更多信息。