HI all,

My
I am trying to convert character date (mm/dd/yy)  to YYYY-mm-dd date
format in one of the columns of my data file.

The first few lines of the data file looks like as follow

 head(Atest,10);dim(Atest)
      ddate
1  19/08/21
2  30/04/18
3  28/08/21
4  11/10/21
5  07/09/21
6  15/08/21
7  03/09/21
8  23/07/18
9  17/08/20
10 23/09/20
[1] 1270076       1

I am using the following different scenarios but none of them resulted
the desired result.

library(data.table)
library(stringr)
library(lubridate)
        Atest$ddate1 <- as.Date((Atest$ddate), format = "%m/%d/%y")
        Atest$ddate2 <- mdy((Atest$ddate))
        Atest$ddate3 <= as.Date(as.character(Atest$ddate),format="%m/%d/%y")
        Atest$ddate4 <- as.Date(as.character(Atest$ddate),"%m/%d/%y")
        Atest$ddate5 <- lubridate::mdy(Atest$ddate)

> head(Atest,3)
     ddate     ddate1 ddate2 ddate4 ddate5
1 19/08/21   <NA>   <NA>   <NA>   <NA>
2 30/04/18   <NA>   <NA>   <NA>   <NA>
3 28/08/21   <NA>   <NA>   <NA>   <NA>


Any help why I am not getting the desired result.
Thank you,

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to