[R] Date Math

PIKAL Petr petr.pikal at precheza.cz
Mon Oct 15 08:16:18 CEST 2012


Hi

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Noah Silverman
> Sent: Sunday, October 14, 2012 7:14 PM
> To: R-help at r-project.org
> Subject: [R] Date Math
> 
> Hello,
> 
> 
> I have a time series object (xts) that I iterate over in a loop.  Works
> fine.
> 
> My challenge is that I want to be able to reference other entries in
> the series by math.  i.e.  For today's observation, what were the last
> 5 observations?  If indexed numerically, it is trivial, but I can
> figure out how to do this with dates.
> 
> This is slightly more difficult as there may not be an observation for
> every day.  So I might want the last 5 that exist in the table, not the
> last 5 calendar days.
> 
> ideally, it would be something like this.
> 
> observations[ index(today)-5:today,  ]
> 
> However that obviously fails.

I would say that you are looking for ?embed. However it does not give you observations from last five days but from any last 5 existing observations regardless of time span.

Regards
Petr


> 
> Ideas?
> 
> 
> 
> --
> Noah Silverman, M.S.
> UCLA Department of Statistics
> 8117 Math Sciences Building
> Los Angeles, CA 90095
> 
> ______________________________________________
> R-help at 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.




More information about the R-help mailing list