Convert Excel numeric to date

后端 未结 3 1929
轮回少年
轮回少年 2020-12-11 06:08

I have a vector of numeric excel dates i.e.

date <- c(42963,42994,42903,42933,42964)

The output am I expecting when using

3条回答
  •  余生分开走
    2020-12-11 06:43

    You can simply use as.Date and specify the origin, i.e.

    as.Date(date, origin="1899-12-30") 
    #[1] "2017-08-16" "2017-09-16" "2017-06-17" "2017-07-17" "2017-08-17"
    
    #or format it to your liking,
    
    format(as.Date(date, origin="1899-12-30"), '%b %Y') 
    #[1] "Aug 2017" "Sep 2017" "Jun 2017" "Jul 2017" "Aug 2017"
    

    This link gives quite a bit of information on this matter.

提交回复
热议问题