Marsenau
Marsenau

Reputation: 1155

seq() skipping a value in the sequence

In an attempt to set up an hourly time series in R I came across the following.

time_index <- seq(from = as.POSIXct("2015-01-01 00:00"), 
                  to = as.POSIXct("2015-03-31 23:00"), by = "hour")
len(time_index)
[1] 2159

From Jan 1st to the end of March in 2015 there are 31+28+31=90 days. So I expected seq to return a sequence of length 24*90 = 2160, however it seems to be short one number. After a little investigation I noticed

time_index[1+66*24+1]
[1] "2015-03-08 01:00:00 EST"
time_index[1+66*24+2]
[1] "2015-03-08 03:00:00 EDT"

That the 8th of March is missing an hour. What is going on with seq() here? Have I made a simple mistake that I am missing?

Upvotes: 2

Views: 449

Answers (1)

John Coleman
John Coleman

Reputation: 52008

The discrepancy is due to daylight savings time.

March 8, 2015 lost an hour: https://www.timeanddate.com/time/change/usa/new-york?year=2015

Upvotes: 6

Related Questions