I have some odd looking variables which I need to convert into a Date class:
dates <- c(" 26JUL2018:23:59:59", " 02APR2018:23:59:59", " 02MAY2018:23:59:59",
" 22APR2018:23:59:59", " 27MAY2018:23:59:59", " 04MAR2018:23:59:59",
" 10APR2018:23:59:59", NA, " 04SEP2018:23:59:59", " 21APR2017:23:59:59"
)
> dates
[1] " 26JUL2018:23:59:59" " 02APR2018:23:59:59" " 02MAY2018:23:59:59"
[4] " 22APR2018:23:59:59" " 27MAY2018:23:59:59" " 04MAR2018:23:59:59"
[7] " 10APR2018:23:59:59" NA " 04SEP2018:23:59:59"
[10] " 21APR2017:23:59:59"
I tried the following which just produces NAs:
as.POSIXct(dates, format=" %d%m%Y:%H:%M:%S")
as.POSIXct(dates, format=" %d%mm%Y:%H:%M:%S")
I also tried removing the spaces using gsub, then using format="%d%m%Y:%H:%M:%S" and format="%d%mm%Y:%H:%M:%S" but neither worked.
What is the correct way to format this vector into class Date?