Geetika Bansal
Geetika Bansal

Reputation: 1

Importing Data in R based on Dates

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?

Upvotes: 0

Views: 63

Answers (1)

rsoren
rsoren

Reputation: 4206

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

Upvotes: 1

Related Questions