Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have date in Excel as follows, first col1 as char and from col2 to col5 is in date format (mm/dd/yyyy)

id   1/1/2016   2/1/2016  3/1/2016  4/1/2016  5/1/2016
1     23         545       33         55          66
2     454        536       66         80          11
3     83         585        9         10          19

I tried to import the above file in to R using readxl library, and my result shows column names which are in date format shows as number in dataset,

How to import Excel date column with same format?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
538 views
Welcome To Ask or Share your Answers For Others

1 Answer

As the dataset is in excel format, we can read it with read_excel and then change the column names to its original format

library(readxl)
library(dplyr)
read_excel("yourdata.xlsx" %>% 
    setNames(., c('id', format(as.Date(as.numeric(names(.)[-1]), 
                   origin = '1899-12-30'), '%m/%d/%Y')))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...