Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying as.Date to Excel format dates in R

Tags:

date

format

r

excel

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"
like image 316
Lorenzo Rigamonti Avatar asked Mar 05 '14 08:03

Lorenzo Rigamonti


1 Answers

"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.

like image 127
G. Grothendieck Avatar answered Nov 08 '22 14:11

G. Grothendieck