简体   繁体   中英

How to Subset xts file with date object?

I searched for quite a while on this question, but can't find an answer. The challenge is finding a way to subset an xts file by date with the form:

 dat <- xts(1:10, as.Date("2000-01-01")+1:10)
 date.1 <-as.Date("2000-01-05")
 dat.subset <-dat[date.1/]

This doesn't work, of course, and neither do variations, such as:

dat.subset <-dat["date.1/"]

How can I subset with the date.1 object to produce the equivalent of:

dat.subset <-dat['2000-01-05/']
dat.subset <-dat[paste0(date.1, "/")]

This should work

require(xts)
dat <- xts(1:10, as.Date("2000-01-01")+1:10)
date.1 <-as.Date("2000-01-05")
dat[date.1,1] #The row name is date.1

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