user4275591
user4275591

Reputation:

Does R use 0-indexing for dates?

R uses the date "1970-01-01" as an origin. Does it make an exception from its typical 1-indexing to index dates with 0-indexing?

> x <- as.Date("1970-01-01")
> y <- as.Date("1970-01-02")

> unclass(x)
[1] 0

> unclass(y)
[1] 1

Upvotes: 1

Views: 121

Answers (1)

MrFlick
MrFlick

Reputation: 206207

No. This is not an indexing thing. "Dates are represented as the number of days since 1970-01-01" (From the ?Date help page). Also note

unclass(as.Date("1969-12-31")) == -1

So it's not an index, it's a difference from a sentinel value. There's no underlying vector here.

Upvotes: 3

Related Questions