0

I want to import an excel file in R. The file however has columns such as Jan-13, Jan14 and so on. These are the column headers. When I import the data using the readxl package, it by default converts the date into numbers. So my columns which should be dates are now numbers. I am using the code :

library(readxl)
data = read_excel("FileName", col_names = TRUE, skip = 0)

Can someone please help?

Jaap
  • 81,064
  • 34
  • 182
  • 193
  • 1
    Change them in Excel to format="text'. – IRTFM Jan 29 '16 at 07:25
  • Could you include a small example of the numbers you are getting and the date-values you expect? You might want to read [Ask] and how to make a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610) in order to get the best possible answer for your problem. – Jaap Jan 29 '16 at 07:45

1 Answers1

1

The date information is still there. It's just in the wrong format. This should work:

names(data) <- format(as.Date(as.numeric(names(data), origin="1899-01-01")), "%b%d")
rsoren
  • 4,036
  • 3
  • 26
  • 37
  • 1
    The origin of date in Excel is dependent of the OS, if I am not mistaken. –  Jan 29 '16 at 07:43
  • I saw that documentation too. I tried it both ways and got the same result though, which, for some reason, is exactly 1 day higher than the input dates. Does anyone have a tweak for that? – rsoren Jan 29 '16 at 07:48