Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date changes while importing excel file in R

Tags:

date

format

r

I have multiple excel files (160) where one 'date' column about 100 observations is in not in proper format. While exporting all the files together the date column changes as follows

Date Column in Excel

Date
05-07-2015
04-07-2015
03-07-2015
02-07-2015
.......

Date column importing in R

Date
42190
42189
42188
42187
......

How to change "42191" to original date format?

like image 275
Sumaiya Khatun Avatar asked Dec 07 '25 05:12

Sumaiya Khatun


1 Answers

Excel may save dates as numeric or maybe they imported in a numeric format. So you can try:

# from Windows Excel:
as.Date(42190, origin = "1899-12-30")
[1] "2015-07-05"

# from Mac Excel: 
as.Date(42190, origin = "1904-01-01")

Interestingly, Excel support page define the origin date for Windows excel as "1900-01-01", but from here and here you can see that for R, date of "1899-12-30" should use as the origin date.

like image 143
A. Suliman Avatar answered Dec 09 '25 20:12

A. Suliman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!