I have a csv file which has date in following format.
date<-c("2018-08-11 03-PM","2018-02-11 05-AM","2018-08-11 01-AM")
How can I convert it to Date in order to sort them by day and time?
I have a csv file which has date in following format.
date<-c("2018-08-11 03-PM","2018-02-11 05-AM","2018-08-11 01-AM")
How can I convert it to Date in order to sort them by day and time?
One line solution-
date<-sort(as.Date(c("2018-08-11 03-PM","2018-02-11 05-AM","2018-08-11 01-AM")))
Edit:
you need to remove -
from time part-
date <- stringi::stri_replace_last_fixed(date, '-', ' ')
sort(lubridate::ydm_h(date))