1
votes

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/']
2

2 Answers

1
votes
dat.subset <-dat[paste0(date.1, "/")]
0
votes

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