R Convert to date from multiple formats

后端 未结 2 1402
花落未央
花落未央 2021-01-19 04:19

I need to convert a string of dates that is in multiple formats to valid dates.

e.g.

dates <- c(\"01-01-2017\",\"02-01-2017\",\"12-01-2016\",\"20         


        
2条回答
  •  再見小時候
    2021-01-19 05:23

    I have tried library(anytime), however for big data did not work. Then, I found useful this sequence:

    df$Date2 <- format(as.Date(df$Date, format="%m/%d/%Y"), "%d/%m/%y")
    
    df$Date2 <- as.Date(df$Date2,"%d/%m/%y")
    

    It worked for me to "8/10/2005" as well as "08/13/05" in the same column.

提交回复
热议问题