Convert yyyymmdd string to Date class in R

后端 未结 4 2176
时光取名叫无心
时光取名叫无心 2020-11-29 07:03

I would like to convert these dates with format YYYYMMDD to a Date class.

dates <- data.frame(Date = c(\"20130707\", \"20130706\", \"20130705\", \"2013070         


        
4条回答
  •  一个人的身影
    2020-11-29 08:01

    Use the lubridate package for an easy conversion:

    date_test <- data.frame(Date = c("20130707", "20130706", "20130705", "20130704"))
    date_test$Date <- ymd(date_test$Date)
    
    date_test
            Date
    1 2013-07-07
    2 2013-07-06
    3 2013-07-05
    4 2013-07-04
    

提交回复
热议问题