Return data subset time frames within another timeframes?

前端 未结 3 582
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 17:01

There are very nifty ways of subsetting xts objects. For example, one can get all the data for all years, months, days but being strictly between 9:30 AM and 4

3条回答
  •  死守一世寂寞
    2020-11-29 17:23

    Be aware that there appears to be different behavior for xts subsetting of a yearmon date format for windows and ubuntu.

    library(quantmod)
    library(xts)
    
    getSymbols("SPY", src="google", from = "2004-01-01")
    x1 <- SPY['2006-01/2007-12']
    
    x2 <- apply.monthly(x1,mean)
    x2['2006-01/2007-12']
    
    x3 <- as.xts(coredata(x2),order.by = as.yearmon(index(x2)))
    x3['2006-01/2007-12']
    

    The result for x2 is consistent between windows and ubuntu, since the format is full date. However, the x3 will produce different result for windows and ubuntu, after the conversion of the dates to yearmon.

提交回复
热议问题