Convert integer as “20160119” to different columns of “day” “year” “month”

后端 未结 5 1435
走了就别回头了
走了就别回头了 2020-12-06 15:30

How can I convert a column of integers as dates:

       DATE PRCP
1: 19490101   25
2: 19490102    5
3: 19490118   18
4: 19490119  386
5: 19490202   38
         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-06 16:14

    I would advise you to use the lubridate package:

    require(lubridate)
    df[, DATE := ymd(DATE)]
    df[, c("Day", "Month", "Year") := list(day(DATE), month(DATE), year(DATE))]
    df[, DATE := NULL]
    

提交回复
热议问题