On Tue, Jun 12, 2012 at 9:48 PM, Matthew Johnson <mcoog...@gmail.com> wrote: > Dear R experts, > > I am learning the very useful XTS package, but cannot figure out the > purpose of some commands. > > in particular, the .indexDate() command does not work as expected. > > say: > > x <- timeBasedSeq('2010-01-01/2010-01-02 12:00') > x <- xts(1:length(x), x) > > then i can subset on date as follows: > > x['2010-01-01'] > > however the .indexDate() command does not work as expected; in > particular the following does not return anything. > > x[.indexDate(x) == '2010-01-01'] > That's because all comparisons are FALSE. .indexDate() returns the index of x, converted to the numeric representation of the Date class (i.e. as.Date(.indexDate(x), origin="1970-01-01") will be the Date of the index values). '2010-01-01' is a character string.
> > I am sure i am missing something - what is .indexDate() supposed to do? > Though it's not well documented, what it's doing is pretty clear from the source: R> .indexDate function (x) { .index(x)%/%86400L } <environment: namespace:xts> > > thanks and best regards > > > matt johnson > Best, -- Joshua Ulrich | FOSS Trading: www.fosstrading.com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.