Convert yyyymmdd string to Date class in R

后端 未结 4 2172
时光取名叫无心
时光取名叫无心 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 07:51

    You need to provide the Date column, not the entire data.frame.

    R> as.Date(dates[["Date"]], "%Y%m%d")
    [1] "2013-07-07" "2013-07-06" "2013-07-05" "2013-07-04"
    

提交回复
热议问题