subsetting in xts using a parameter holding dates

前端 未结 4 772
慢半拍i
慢半拍i 2020-12-18 06:04

I am familiar with the xts subsetting abilities. However, I can\'t find an elegant way to subset a parameterized range of dates. something like this:

<
4条回答
  •  情深已故
    2020-12-18 06:14

    For those who are racking their brain to do this for non Posix. Especially for quarter based data i.e. 2001 Q2 to 2006 Q3.

    I used a simple yet elegant solution:

    library(xts)
    
    starting.quarter<-"200101"
    ending.quarter<-"201702"
    
    oil_price_by_qtr<-oil_price_by_qtr[paste(starting.quarter,ending.quarter,sep="/")]
    

    And this will subset the XTS object from 2001 Q1 to 2017 Q2.

    May this help some other poor soul avoid losing 2 hours of his life.

提交回复
热议问题