Skip to content
Prev 307984 / 398503 Next

Date Math

On 12-10-15 06:00 AM, r-help-request at r-project.org wrote:
Switching between 5 entries back and 5 days back has me confused about 
whether you have more than one entry some days or not. If you mean you 
have at most one entry per day, and you want the last five days that you 
have observations, then this part of your problem can be solved by 
switching from POSIXct to dates:
 >  z <-  Sys.time()
 > z
[1] "2012-10-15 08:34:58 EDT"
 > z -5
[1] "2012-10-15 08:34:53 EDT"
 > as.Date(z) -5
[1] "2012-10-10"

(BTW, a complete example is always useful when asking for help. I think 
your "obviously fails" code would be pretty close to working, depending 
on how the dates were generated.)

Paul