read.xls not behaving as expected

110 Views Asked by At

I have a excel file (in xls format) like this

a             b
10/06/2012  10/06/12 19:00
11/06/2012  11/06/12 05:30
11/06/2012  11/06/12 09:30
11/06/2012  11/06/12 10:00 
11/06/2012  11/06/12 11:00
11/06/2012  11/06/12 11:30

I am using read.xls function of gdata library to read this xls file into R.

data <- read.xls("data.xlsx")

But when open this file in R. I get this

a                b
41070          41070.79
41071          41071.23
41071          41071.40
41071          41071.42
41071          41071.46
41071          41071.48

I do not know what is happening here. When I use read.csv to read the converted csv file, the file is being read correctly. Can somebody please tell me what is the problem? I am working on Linux machine.

2

There are 2 best solutions below

0
On

Excel stores dates as numbers: http://office.microsoft.com/en-001/excel-help/about-dates-and-date-systems-HP005200674.aspx.

What you got from Excel is precisely those numbers (no. of days which elapsed from January 1, 1900 till your dates.

A way to get your strings unchanged to R would be to convert them in Excel to pure text strings first.

0
On

Try to format the date in the R readable format 2014-11-25. Then read.xls would work properly. If you need it in the same format try using XLConnect.