Lorenzo Rigamonti
Lorenzo Rigamonti

Reputation: 1775

Applying as.Date to Excel format dates in R

I want to convert an Excel format date into yyyy-mm-dd in order to convert a data.frame in a zoo object.

Using the two following formulas does not give the same result?

Why does that happen?

> as.Date(41375, origin = "1899-12-30")
[1] "2013-04-11"

> as.Date(41375, tz = "CET")
[1] "2083-04-13"

Upvotes: 6

Views: 6164

Answers (1)

G. Grothendieck
G. Grothendieck

Reputation: 269596

"Date" class has no time zones so tz= is meaningless. I assume you have the zoo package loaded in which case origin = "1970-01-01" is supplied as the default so the second line of code in the question is the same as:

as.Date(41375, origin = "1970-01-01")

There is a discussion of Excel dates and R in the Help Desk article of R News 4/1.

Upvotes: 7

Related Questions