Converting to date in a character column that contains two date formats

后端 未结 4 1025

I have CSV file with \"date\" column but it contains two different date format as the following

7/12/2015 15:28 as m/d/yyyy hh:mm
18-04-2016 18:20  as d/m/yy         


        
4条回答
  •  眼角桃花
    2020-12-06 14:36

    Here is another option with lubridate

    library(lubridate)
    parse_date_time(x, c("mdy HM", "dmy HM"))   
    #[1] "2015-12-07 15:28:00 UTC" "2016-04-18 18:20:00 UTC"
    

    data

    x <- c("7/12/2015 15:28","18-04-2016 18:20")
    

提交回复
热议问题